Binary number manipulation

Bill Sneddon bsneddonNOspam at yahoo.com
Wed Dec 3 19:39:45 CET 2003


Georgy Pruss wrote:
> "Tim Roberts" <timr at probo.com> wrote in message news:350rsvkbsht8rgs1fsjjc7vkktf87sahi7 at 4ax.com...
> | SBrunning at trisystems.co.uk wrote:
> | >
> | >> 2. If 1 is no, does that mean that I need to do all the manipulation in
> | >> some icky string format and then go back?
> | >
> | >I use:
> | >
> | >((high << 16) | low)
> |
> | ...which, unfortunately, gives a FutureWarning in Python 2.3 if high
> | happens to be larger than 32767.
> 
> Yes, it's really annoying. I use (high * 65536 + low) instead.
> 
> -Georgy
> 
> 
Were are you getting you numbers from?
Have you looked at the struct module?

I am reading a binary file and use this command from struct module to
convert to integer not sure if this helps you or not.

mwB =  struct.unpack('>H',mw)[0]  # unpack big-endian unsigned short 
..detuple it






More information about the Python-list mailing list