Converting two BYTEs into a WORD
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Converting two BYTEs into a WORD

  1. #1
    Join Date
    Oct 2005
    Location
    England
    Posts
    36

    Converting two BYTEs into a WORD

    Hi,

    How do I copy two BYTEs into a WORD (two bytes)?

    Many thanks

    Mark

  2. #2
    Join Date
    Jan 2002
    Location
    Houston, TX
    Posts
    1,421

    Re: Converting two BYTEs into a WORD

    One way:

    Code:
    WORD myWordVal = 0;
    BYTE myByte1 = 17;
    BYTE myByte2 = 45;
    
    myWordVal = myByte1 <<  8 + myByte2;
    Be sure to rate those who help!
    -------------------------------------------------------------
    Karl - WK5M
    PP-ASEL-IA (N43CS)
    PGP Key: 0xDB02E193
    PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193

  3. #3
    Join Date
    Sep 2002
    Location
    14 39'19.65"N / 121 1'44.34"E
    Posts
    9,815

    Re: Converting two BYTEs into a WORD

    Quote Originally Posted by mjseaden
    How do I copy two BYTEs into a WORD (two bytes)?
    You can use the MAKEWORD macro for that:
    Code:
    BYTE loByte = 17;
    BYTE hiByte = 45;
    
    WORD wordVal = MAKEWORD(loByte, hiByte);

  4. #4
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: Converting two BYTEs into a WORD

    Yes, that is true, but you have to include "windows.h" for that.
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center