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
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 <<
+ low_byte
you can pointers, gets little more complicated.
- ben
1) unsigned int word = high_byte * 256 + low_byte;
2) unsigned int word = ((unsigned int)high_byte <<
+ low_byteyou 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
Post a Comment