I can only answer half your question. The sign bit in a long is bit 31. So when you shift right 8 bits, it moves the sign bit as well, which shows up as bit 23 after your shift. To fix that, read the sign bit, clear the sign bit, then shift, then set the sign bit again.
However, the value you are getting is 111111111111111111111111 in binary. And that does not make sense ... to me anyway. I would have expected 100000000000000000000001
But, are you dividing by 256 because of a sensor value? If so, shouldn't you be dividing by 255? Otherwise 5 volt reading will never be reached with divisor of 256. Divisor by 255, and it is possible to get to 5 volts.
Bookmarks