Thread: combining array indicies to form a new type

  1. #1
    Registered User
    Join Date
    Oct 2004
    Posts
    100

    combining array indicies to form a new type

    hey all,

    I have a byte array with 16 indicies. Is there a way that I can create a new type from combining 2 of the indicies of the array together (which will create a WORD). The word only needs to be a pointer to the array.

    So if i have

    [code]
    Byte byteA[16];
    Word word = // byteA[4] + byteA[7];
    [code]

    So the variable "word" will have the higher byte stored in byteA[4] and the lower byte in byteA[7].

    I hope I have explained this clearly enough

    Thanks

  2. #2
    Tropical Coder Darryl's Avatar
    Join Date
    Mar 2005
    Location
    Cayman Islands
    Posts
    503
    in windows.h there is a macro MAKEWORD that does what you want. In case you're not on windows it's defined:

    Code:
     #define MAKEWORD(a, b)      ((WORD)(((BYTE)((DWORD_PTR)(a) & 0xff)) | ((WORD)((BYTE)((DWORD_PTR)(b) & 0xff))) << 8))
    note that it takes the low byte as the first parameter

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM
  3. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  4. ras.h errors
    By Trent_Easton in forum Windows Programming
    Replies: 8
    Last Post: 07-15-2005, 10:52 PM
  5. gcc problem
    By bjdea1 in forum Linux Programming
    Replies: 13
    Last Post: 04-29-2002, 06:51 PM