Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Getting Last Two Bytes

Getting Last Two Bytes

Scheduled Pinned Locked Moved C / C++ / MFC
question
6 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    RS Ratheesh
    wrote on last edited by
    #1

    Hi, I need to take last two bytes from unsigned integer. How can i get it. Ratheesh,

    J C C K 4 Replies Last reply
    0
    • R RS Ratheesh

      Hi, I need to take last two bytes from unsigned integer. How can i get it. Ratheesh,

      J Offline
      J Offline
      Jijo Raj
      wrote on last edited by
      #2

      Hello Ratheesh, You can use LOWORD()[^] macro to get the last two bytes together. If you need last two bytes separately, then call LOWORD()[^] to get last two bytes together and then get bytes separately by calling LOBYTE()[^] and HIBYTE()[^] macros. Regards, Jijo.

      _____________________________________________________ http://weseetips.com[^] Visual C++ tips and tricks. Updated daily.

      modified on Friday, June 12, 2009 7:43 AM

      1 Reply Last reply
      0
      • R RS Ratheesh

        Hi, I need to take last two bytes from unsigned integer. How can i get it. Ratheesh,

        C Offline
        C Offline
        CPallini
        wrote on last edited by
        #3

        ratheeshnair123 wrote:

        last two bytes

        it is a bit ambiguous... :rolleyes:

        If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
        This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
        [My articles]

        1 Reply Last reply
        0
        • R RS Ratheesh

          Hi, I need to take last two bytes from unsigned integer. How can i get it. Ratheesh,

          C Offline
          C Offline
          chirag_chauhan
          wrote on last edited by
          #4

          You can also achieve the results using & and shift-operators. Something like unsigned-var & 3 (as last 2 bits are 1s and all others are 0s) and then do left-shift to get last 2 bits.

          P 1 Reply Last reply
          0
          • C chirag_chauhan

            You can also achieve the results using & and shift-operators. Something like unsigned-var & 3 (as last 2 bits are 1s and all others are 0s) and then do left-shift to get last 2 bits.

            P Offline
            P Offline
            PandemoniumPasha
            wrote on last edited by
            #5

            no need to left shift the bits. they are already in the required order.

            regards :)

            1 Reply Last reply
            0
            • R RS Ratheesh

              Hi, I need to take last two bytes from unsigned integer. How can i get it. Ratheesh,

              K Offline
              K Offline
              krmed
              wrote on last edited by
              #6

              Another option is to use the modulus operator:

              int i = 0;
              int x = 0;
              i = 1286439; // i is now 0x13A127
              x = i % 65536; // x is now 0xA127

              Just another way to do the same thing.

              Karl - WK5M PP-ASEL-IA (N43CS) PGP Key: 0xDB02E193 PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups