Byte type advice

Fredrik Lundh fredrik at pythonware.com
Wed Oct 20 04:21:18 EDT 1999


Scott Barron <kain at twilight.> wrote:
> Is there any Byte type in Python?  What I am specifically trying to do
> is port some VB code which has a Byte type defined as an unsigned 8-bit
> number.  Would it be safe to use a regular Python number type, or am I
> going to have to do more work?

python integers correspond to long integers
in C, and are usually signed 32-bit values.

you can probably use them in this case, but
you have to watch out for places where your
program expects some special behaviour from
the byte variables (such as wraparound, or
truncation to 8 bits, or something).  you might
need to insert "& 0xff" or even "% 0xff" in some
places.  it all depends on the code...

use chr() and ord() to convert to and from binary
strings.

</F>

<!-- (the eff-bot guide to) the standard python library:
http://www.pythonware.com/people/fredrik/librarybook.htm
-->





More information about the Python-list mailing list