"Craig" <[EMAIL PROTECTED]> wrote:
> Hi there,
>
> I'm trying to switch binary numbers around so that the MSB becomes the
> LSB etc. Is there an easy way of doing this as I can't seem to find
> anything. If you could help that would be great. Thank
Terry Reedy wrote:
> "Craig" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
> > Thanks so much for the response. I have an array of individual bytes
> > which will eventually make up a binary bitmap image that is loaded onto
> > an LCD screen (1 = black dot, 0 = white dot). At th
"Craig" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Thanks so much for the response. I have an array of individual bytes
> which will eventually make up a binary bitmap image that is loaded onto
> an LCD screen (1 = black dot, 0 = white dot). At the moment each byte
> is rever
On Dec 6, 7:20 pm, Grant Edwards <[EMAIL PROTECTED]> wrote:
> It's a little less obtuse if you spell it this way:
>
> def flipbits(x):
> """reverse bits in a byte"""
> x1 = x << 4 | x >> 4
> x2 = (x1 & 0x33) << 2 | (x1 & 0xcc) >> 2
> return (x2 & 0x55) << 1 | (x2 & 0xaa) >> 1
>
G
On 2006-12-06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> Yet another solution:
>
> def flipbits(x):
> """reverse bits in a byte"""
> x1 = x << 4 | x >> 4
> x2 = (x1 & 51) << 2 | (x1 & 204) >> 2
> return (x2 & 85) << 1 | (x2 & 170) >> 1
>
> The idea is to first swap the two nyb
On Dec 6, 6:01 pm, "Craig" <[EMAIL PROTECTED]> wrote:
> Thanks so much for the response. I have an array of individual bytes
> which will eventually make up a binary bitmap image that is loaded onto
> an LCD screen (1 = black dot, 0 = white dot). At the moment each byte
> is reversed to what it s
Craig wrote:
> Matimus wrote:
>
> > Craig wrote:
> > > I'm trying to switch binary numbers around so that the MSB becomes the
> > > LSB etc.
> >
> > What do you mean 'binary numbers'? They are all binary. If you mean the
> > int ty
On 2006-12-06, Craig <[EMAIL PROTECTED]> wrote:
> Thanks so much for the response. I have an array of
> individual bytes which will eventually make up a binary bitmap
> image that is loaded onto an LCD screen (1 = black dot, 0 =
> white dot). At the moment each byte is reversed to what it
> shou
Matimus wrote:
> Craig wrote:
> > I'm trying to switch binary numbers around so that the MSB becomes the
> > LSB etc.
>
> What do you mean 'binary numbers'? They are all binary. If you mean the
> int type, they are 32 bits long and there are 16 bit
Craig wrote:
> I'm trying to switch binary numbers around so that the MSB becomes the
> LSB etc.
What do you mean 'binary numbers'? They are all binary. If you mean the
int type, they are 32 bits long and there are 16 bits between the MSB
and LSB (Most/Least Significant _B
Hi there,
I'm trying to switch binary numbers around so that the MSB becomes the
LSB etc. Is there an easy way of doing this as I can't seem to find
anything. If you could help that would be great. Thanks and good
luck.
Craig
--
http://mail.python.org/mailman/listinfo/python-list
> Em Quarta 08 Junho 2005 09:38, Guyon Morée escreveu:
> > Don't know if this is what you mean, but:
> >
> > Binary to decimal:
> > >>> bin_num = '11011'
> > >>> int(bin_num, 2)
> >
> > 267
>
> Dont know this way of using it. Thanks for the teachings :)
>
> See ya !
>>> def binary(i):
..
Hi!
Em Quarta 08 Junho 2005 09:38, Guyon Morée escreveu:
> Don't know if this is what you mean, but:
>
> Binary to decimal:
> >>> bin_num = '11011'
> >>> int(bin_num, 2)
>
> 267
Dont know this way of using it. Thanks for the teachings :)
See ya !
--
Douglas Soares de Andrade
http://douglas
Don't know if this is what you mean, but:
Binary to decimal:
>>> bin_num = '11011'
>>> int(bin_num, 2)
267
>>> def dec2bin(dec_number):
... if dec_number == 0: return '0'
... return (dec2bin(dec_number >> 1) + str(dec_number % 2))
...
>>> dec2bin(267)
'011011'
--
Guyon Morée
[EM
Douglas Soares de Andrade wrote:
> Hi !
>
> How to work with binary numbers in python ? Is there a way to print a number
> in its binary form like we do with oct() or hex() ?
>
> Im doing a project that i have to work with binaries and i tired of convert
> numbers to s
Douglas Soares de Andrade wrote:
> Hi !
>
> How to work with binary numbers in python ? Is there a way to print a number
> in its binary form like we do with oct() or hex() ?
This is a popular topic in the Python Cookbook, maybe one of these recipes will
suit you:
http://aspn.act
Hi !
Pardon me, but what itoa has to do it the history ?
See ya !
Em Quarta 08 Junho 2005 00:34, Dan Bishop escreveu:
> Douglas Soares de Andrade wrote:
> > Hi !
> >
> > How to work with binary numbers in python ? Is there a way to print a
> > number in its binary fo
Douglas Soares de Andrade wrote:
> Hi !
>
> How to work with binary numbers in python ? Is there a way to print a number
> in its binary form like we do with oct() or hex() ?
>
> Im doing a project that i have to work with binaries and i tired of convert
> numbers to string al
Hi !
How to work with binary numbers in python ? Is there a way to print a number
in its binary form like we do with oct() or hex() ?
Im doing a project that i have to work with binaries and i tired of convert
numbers to string all the time to perform some operations.
I searched about it in
19 matches
Mail list logo