Bit Operations

Chris Mellon arkanes at
Wed Nov 28 21:34:29 CET 2007

On Nov 28, 2007 2:27 PM, Chris Mellon <arkanes at> wrote:
> On Nov 28, 2007 2:07 PM, Gianmaria Iaculo - NVENTA
> <gianmaria at> wrote:
> > Hi there,
> > I'm so new to python (coming from .net so excuse me for the stupid question)
> > and i'm tring to do a very simple thing,with bytes.
> >
> > My problem is this:
> >
> > i've a byte that naturally is composed from 2 nibbles hi&low, and two
> > chars.. like A nd B. What i wonna do is to write A to the High nibble and B
> > to the the lower nibble.
> A string in python is a sequence of bytes, so what you're describing
> here is the string "AB".

Ah, I didn't realize until after I'd sent this that you were trying to
merge them into the same byte. This doesn't make a whole lot of sense
- ord("A") is outside the range you can represent in half a byte - but
Python does support the full range of bitwise operations, so you can
do whatever kind of shifting and setting that you'd have done in .NET.

More information about the Python-list mailing list