[Tutor] how to read one bit of a byte

shawn bright nephish at gmail.com
Wed Feb 21 05:40:30 CET 2007


great, thanks for this. appreciate it a lot.

sk

On 2/20/07, Luke Paireepinart <rabidpoobear at gmail.com> wrote:
>
> shawn bright wrote:
> > lo there all,
> >
> > i am reading a binary file with open('myfile', 'rb')
> >
> > then i do a read(1) to read one byte. cool so far.
> >
> > but how do i read the individual bits of a byte
> >
> > i mean if i have a = read(1)
> >
> > how do i know what the msb of a is ?
> >
> > i need to know because i have to see if the msb is set and i also need
> > to know the value of the next bit.
> Well, you know the value of the MSB is...
> 1 2 4 8 16 32 64 128
> so if you divide the value by 128, and get a 1 and not a 0, then it's set.
> People commonly write functions to make binary lists from values.
> -Luke
> >
> > any tips would be greatly appreciated.
> >
> > thanks
> > ------------------------------------------------------------------------
> >
> > _______________________________________________
> > Tutor maillist  -  Tutor at python.org
> > http://mail.python.org/mailman/listinfo/tutor
> >
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070220/7557e2e1/attachment.htm 


More information about the Tutor mailing list