CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11
  1. #1
    Join Date
    May 2004
    Location
    Malaysia
    Posts
    108

    Exclamation what is HIBYTE, LOBYTE, HIWORD, LOWORD

    LOBYTE, HIBYTE, HIWORD, LOWORD. What does these terms means? I am new to these stuff and msdn doesn provide much information about those stuff.. Please teach me..

    THank YOu @!

  2. #2
    Join Date
    Jun 2004
    Location
    India
    Posts
    432
    They are macros.

    #define LOWORD(l) ((WORD)(l))
    #define HIWORD(l) ((WORD)(((DWORD)(l) >> 16) & 0xFFFF))
    #define LOBYTE(w) ((BYTE)(w))
    #define HIBYTE(w) ((BYTE)(((WORD)(w) >> 8) & 0xFF))


    LOWORD gets the lower two bytes of a 4 byte value and so on.
    Say no to supplying ready made code for homework/work assignments!!

    Please rate this post!

  3. #3
    Join Date
    May 2004
    Location
    Malaysia
    Posts
    108

    Exclamation

    I got that in msdn and I still couldn understand it? Do you have any sample?

    THank YOu @!

  4. #4
    Join Date
    Jun 2004
    Location
    India
    Posts
    432
    Before I give out samples tell me this

    given an integer 0x12345678

    what are the two lower bytes of that intger?
    what are the two higher bytes of that integer?

    given a short value 0xABCD

    what is the low byte of that value?
    what is the high byte of that value?
    Say no to supplying ready made code for homework/work assignments!!

    Please rate this post!

  5. #5
    Join Date
    Mar 2004
    Location
    (Upper-) Austria
    Posts
    2,899
    plain and simple: the function helps you to get the lowest/highest byte/word of a bigger value:

    an example:


    #define DIGIT 0xFFAC

    // I am flipping stuff today, so do not care if I flipped they two too
    LOBYTE(DIGIT) == 0xAC
    HIBYTE(DIGIT) == 0xFF

    Get it?

    p.s.: Sory for not using the code tag, but my MacExplorer cannot show the correctly
    I am not offering technical guidiance via email or IM
    Come on share your photo with us! CG members photo album!
    Use the Code Tags!

  6. #6
    Join Date
    May 2004
    Location
    Malaysia
    Posts
    108
    Quote Originally Posted by UnderDog
    Before I give out samples tell me this

    given an integer 0x12345678

    ..
    ..

    given a short value 0xABCD

    ..
    ..
    I really don know... Sorry.. But now thanks to NoHero... I understand what it means...

    You know what, I got a sample source code which talk about send a key on keyboard through SendMessage().. From the source code I found this:

    BYTE ScanCode = LOBYTE(::MapVirtualKey(VKey, 0));

    What does it try to do? Is that means MapVirtualKey() will have LOBTYE and HIBYTE?

    OK wait! before I learn SendMessage(), I always confuse the use of WPARAM and LPARAM, until now I know that LOWORD(WPARAM) is refering to the control ID and HIWORD(WPARAM) is refering to the notification message whereas LPARAM is the event.. Am I right? Please correct me if I am wrong..

    Then does that case is same to this case.. I mean LOBYTE will refering to some ID control and then HIBYTE will refering to the notification message? Please corect me..

    THank YOu @!

  7. #7
    Join Date
    May 2004
    Location
    Michigan, United States
    Posts
    457
    The meaning of the WPARAM and LPARAM parameters will be different, depending on which message you are handling. You will need to consult MSDN for an explanation of what WPARAM and LPARAM respresent.

    Each of them is two words (double-word or DWORD) in size. Sometimes, a DWORD is necessary to hold a message parameter. Other times, like in the example you mentioned, a word will suffice. In that case, like in the WM_COMMAND message, two parameters (the control ID and the notificaiton code) which are each a word, can be packed together into a DWORD-sized WPARAM. This can be accomplished by using the MAKEWPARAM (or MAKELPARAM) macros. Using both macros, you can now pass up to four word-sized parameters with a message.

    However, it's up to the client (you) to extract the DWORD values into WORD values. This is done with the LOWORD/HIWORD macros.
    Programming today is a race between software engineers striving to build bigger and better idiot-proof programs and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

  8. #8
    Join Date
    May 2004
    Location
    Malaysia
    Posts
    108
    Hi!! Thanks for your explanation... I feel so happy..

    So... Hmm~ ... Then how about LOBYTE as I mention in the example? Will that case is actually the same as WPARAM/LPARAM?

    THank YOu @!

  9. #9
    Join Date
    May 2004
    Location
    Michigan, United States
    Posts
    457
    Quote Originally Posted by huahsin68
    Hi!! Thanks for your explanation... I feel so happy..

    So... Hmm~ ... Then how about LOBYTE as I mention in the example? Will that case is actually the same as WPARAM/LPARAM?

    THank YOu @!
    No. Remember, those are DWORD's. The LOBYTE macros returns a byte from a WORD.
    Code:
    BYTE  =  8 bits
    WORD  = 16 bits
    DWORD = 32 bits
    So, if you have a DWORD (like WPARAM/LPARAM), you should use the LOWORD/HIWORD macros to retrieve a pair of 16-bit words from a single 32-bit DWORD.

    If you have a 16-bit WORD and need the two 8-bit BYTEs that make up that word, then you'll use LOBYTE/HIBYTE to retrieve them.
    Programming today is a race between software engineers striving to build bigger and better idiot-proof programs and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

  10. #10
    Join Date
    Mar 2007
    Posts
    1

    Re: what is HIBYTE, LOBYTE, HIWORD, LOWORD

    Quote Originally Posted by Bond
    The meaning of the WPARAM and LPARAM parameters will be different, depending on which message you are handling. You will need to consult MSDN for an explanation of what WPARAM and LPARAM respresent.

    Each of them is two words (double-word or DWORD) in size. Sometimes, a DWORD is necessary to hold a message parameter. Other times, like in the example you mentioned, a word will suffice. In that case, like in the WM_COMMAND message, two parameters (the control ID and the notificaiton code) which are each a word, can be packed together into a DWORD-sized WPARAM. This can be accomplished by using the MAKEWPARAM (or MAKELPARAM) macros. Using both macros, you can now pass up to four word-sized parameters with a message.

    However, it's up to the client (you) to extract the DWORD values into WORD values. This is done with the LOWORD/HIWORD macros.
    Thanks Bond, the infermation you have posted here was very useful
    Great !

  11. #11
    Join Date
    May 2004
    Location
    Michigan, United States
    Posts
    457

    Re: what is HIBYTE, LOBYTE, HIWORD, LOWORD

    Quote Originally Posted by omkarhm
    Thanks Bond, the infermation you have posted here was very useful
    Great !
    Wow, this post is a blast from the past. Glad you found the information useful!

    Practice safe programming.
    Programming today is a race between software engineers striving to build bigger and better idiot-proof programs and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured