[Tutor] back on bytes
malaclypse2 at gmail.com
Fri Jul 6 19:48:08 CEST 2007
On 7/6/07, shawn bright <nephish at gmail.com> wrote:
> i have a number 12480
> i have a low byte of 192 and a high byte of 176
Maybe I'm being dense, but that doesn't make any sense at all to me.
The high byte of 12480 is 48, and the low byte is 192, isn't it?
Because (48 * 256) + 192 = 12480?
In your formula ( (176 & 127) * 256 + 192 ) you're only using 7 bits
of your high byte. Why are you masking off that last bit? And if you
mask it off, how do you expect to recover it going the other
direction? I suppose for this particular example, the following would
work, but it doesn't seem like what you really are after:
>>> n = 12480
>>> low_byte = n & 0xFF
>>> hi_byte = n >> 8
# Add the extra bit back in that was masked off
>>> hi_byte = hi_byte+128
More information about the Tutor