Re: Mirror imaging binary numbers

2006-12-07 Thread Hendrik van Rooyen
"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. Thanks and good > luck. Are these Python ints, or

Re: Mirror imaging binary numbers

2006-12-06 Thread Craig
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

Re: Mirror imaging binary numbers

2006-12-06 Thread Terry Reedy
"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

Re: Mirror imaging binary numbers

2006-12-06 Thread dickinsm
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

Re: Mirror imaging binary numbers

2006-12-06 Thread Grant Edwards
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

Re: Mirror imaging binary numbers

2006-12-06 Thread dickinsm
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

Re: Mirror imaging binary numbers

2006-12-06 Thread [EMAIL PROTECTED]
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 type, they are 32 bits long and there are 16 bits between the MSB > >

Re: Mirror imaging binary numbers

2006-12-06 Thread Grant Edwards
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

Re: Mirror imaging binary numbers

2006-12-06 Thread Craig
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 bits between the MSB > and LSB (Most/Least Significa

Re: Mirror imaging binary numbers

2006-12-06 Thread Matimus
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 _Byte_). Do you want to swa

Mirror imaging binary numbers

2006-12-06 Thread Craig
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