two's complement bytes

Adam W. AWasilenko at gmail.com
Sun Aug 24 06:52:52 CEST 2008


On Aug 24, 12:23 am, castironpi <castiro... at gmail.com> wrote:
> Try this out.  Does it come close to what you want?
>
> import struct
> struct.pack( 'i', ~10 )
> ~struct.unpack( 'i', _ )[ 0 ]
>
>
>
>
>
> >>> import struct
> >>> struct.pack( 'i', ~10 )
> '\xf5\xff\xff\xff'
> >>> ~struct.unpack( 'i', _ )[ 0 ]
> 10- Hide quoted text -
>
> - Show quoted text -
Humm, so how do you use it :P  Let me give you some examples and then
you can run it through:

0b1111110010010000 or 0xFC90  Should equal -880
0b0000011111010000 or 0x07D0  Should equal +2000



More information about the Python-list mailing list