era86
Would it kill you to write a 10 line program to figure this out on your own?
If you have a 16-bit value, why don't you tell me which portion of it you want to assign to your 8-bit value... do you want to MSB or the LSB? Depending on what you want, then assign your 8-bit value appropriately, without performing a "lame" cast. For example:
Code:
#include <stdint.h>
...
uint16_t two_bytes = 0xDEAD;
uint8_t one_byte_LSB = two_bytes & 0xFF; // obtains the LSB
uint8_t one_byte_MSB = (two_bytes & 0xFF00) >> 8; // obtains the MSB
P.S.
MSB = Most Significant Byte
LSB = Least Significant Byte
P.S.S.
Code:
#include <stdint.h>
#include <assert.h>
int main()
{
uint16_t value = 0xDEAD;
assert((uint8_t)value == 0xAD);
}
Bookmarks