Hi
I have 3 bytes of data that I am told represent a 24 bit integer. I am also told that the the data is in 2's compliment.
How do i covert the bytes to an integer value
Thanks for your time
Printable View
Hi
I have 3 bytes of data that I am told represent a 24 bit integer. I am also told that the the data is in 2's compliment.
How do i covert the bytes to an integer value
Thanks for your time
Assuming the data is big-endian and that int is 32 bits on your platform. The last shift is to sign extend the result.Code:unsigned char data[3];
int result = ((data[0] << 24) + (data[1] << 16) + (data[2] << 8)) >> 8;
Thanks!!!