example char array loaded from a file:
Code: Select all
char memory[1024] = {
0x10,0x28,0xF0,0xF0 };
Thanks,
Troy
Code: Select all
char memory[1024] = {
0x10,0x28,0xF0,0xF0 };
Code: Select all
uint16_t intvalue = * (uint16_t)&memory[1];
I'm afraid that won't work on quite a few occasions. First, that memory fetch would be misaligned in the example given, which may cause an alignment fault on x86 machines -- and may crash bigendian machines. Second, it won't give you the proper byte order on bigendian machines.JamesM wrote:Cast the relevant area to a 16-bit integer and dereference.
Code: Select all
p = ptr to 1st byte of "16 bit word"
little_endian_word = *p | (p[1] << 8);