combine two 8 bit integers into a 16 bit integer


i have 2 8 bit integers want combine 1 unsigned 16 bit integer.

actually first byte (8 bits) high order bits, second byte low order bits.  i reading these eeprom.  so read these 2 bytes eeprom, , want combine them 1 16 bit unsigned integer.

what "correct" way combine these two?  i guessing there easy way first shift in high order bits, shift in low order bits?

thanks
chad

there few ways can this:

1) unsigned int word = high_byte * 256 + low_byte;

2) unsigned int word = ((unsigned int)high_byte << 8) + low_byte

you can pointers, gets little more complicated.


- ben


Arduino Forum > Forum 2005-2010 (read only) > Software > Syntax & Programs > combine two 8 bit integers into a 16 bit integer


arduino

Comments

Popular posts from this blog

CAN'T INSTALL MAMBELFISH 1.5 FROM DIRECTORY - Joomla! Forum - community, help and support

error: expected initializer before 'void'

CPU load monitoring using GPIO and leds - Raspberry Pi Forums