If I have to handle values to be stored in bytes like 0x118, how do I split the LSB and MSB?
I was trying the following way… I don’t think that it’s the right way:
value = 0x118;
Storing in bytes…
result[5] = (byte) value;
result[6] = (byte)(value << 8);
...
What is the correct way?
This will do it:
I usually use bit masks – maybe they’re not needed. The first line selects the lower eight bits, the second line selects the upper eight bits and shifts the bits eight bit positions to the right. This is equal to a division by 28.
This is the “trick” behind:
To sum it up, do the following calculation: