Home arrow Support arrow Forums

Luminary Micro Forums

ringram2077

Expert Boarder

2006/12/21 09:26

Assign HIGH LOW Bytes of WORD

Hi
When using the uV3 compiler what is the best and easiest method to assign the high and low bytes of a word ?
eg.
High(uns16_number) = uns8_variable1 // assign high byte
Low(uns16_number) = uns8_variable2 // assign low byte

Thanks

Post edited by: ringram2077, at: 2006/12/21 09:26

login or register to reply

igorp

Gold Boarder

2006/12/22 01:37

Re:Assign HIGH LOW Bytes of WORD

Hello,

You could use macro, for instance:

#define High(v) (*(((unsigned char *) (&v)+ 1)))
#define Low(v) (*((unsigned char *) (&v)))

if your compiler uses little Endian.

High(uns16_number) = uns8_variable1; // assign high byte
Low(uns16_number) = uns8_variable2; // assign low byte

or

uns8_variable = High(uns16_number); etc....

Regards

Igor

login or register to reply

ringram2077

Expert Boarder

2006/12/22 17:02

Re:Assign HIGH LOW Bytes of WORD

Thanks!!
That seems to work for me. Now all I need to do is figure out if I an a big endian or a little endian. Let me go measure my arrow :-) .

login or register to reply