On 22 Feb 2005 09:14:50 GMT,
Duncan Booth <[EMAIL PROTECTED]> wrote:
> Here's yet another way to achieve the same results. This version doesn't
> iterate over any bits at all:
import operator
parity = [ False ]
for i in range(7):
> parity += map(operator.not_, parity)
Ver
Dan Sommers wrote:
>> Seems to work, is there a better way to do this?
>
> for c in range( 128 ):
> even_odd = 0
> print '%3d' % c,
> while c:
> c &= c - 1
> even_odd = not even_odd
> print int( even_odd )
>
> Okay, so your inner loop is only counting to 8, but IM
On Mon, 21 Feb 2005 10:55:05 -0800, rumours say that Bryan <[EMAIL PROTECTED]>
might have written:
[I]
is to reset the rightmost (less significant) '1' bit of a number (ie
change it to '0').
[bryan]
>>>i tried c &= c - 1 but i'm not getting the least significant or
>>>rightmost bit reset
"Christos TZOTZIOY Georgiou" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> On 21 Feb 2005 06:48:19 -0500, rumours say that Dan Sommers
> <[EMAIL PROTECTED]>
>>for c in range( 128 ):
>>even_odd = 0
>>print '%3d' % c,
>>while c:
>>c &= c - 1
>>even_odd =
Duncan Booth wrote:
Bryan wrote:
is to reset the rightmost (less significant) '1' bit of a number (ie
change it to '0').
i tried c &= c - 1 but i'm not getting the least significant or
rightmost bit reset to zero. am i misunderstanding something?
2 & 1 # 2 = 0x10; reset right most would be 0x10
Duncan Booth wrote:
The difference between the original "reset the rightmost '1' bit", and your
interpretation: "reset the rightmost bit" is the "'1'".
The rightmost bit that is set is reset. So 0x10 -> 0, and 0x1010 -> 0x1000.
If you want to extract the least significant set bit from a number 'x
Bryan wrote:
>> is to reset the rightmost (less significant) '1' bit of a number (ie
>> change it to '0').
>
> i tried c &= c - 1 but i'm not getting the least significant or
> rightmost bit reset to zero. am i misunderstanding something?
>
> >>> 2 & 1 # 2 = 0x10; reset right most would be 0x1
Christos TZOTZIOY Georgiou wrote:
On 21 Feb 2005 06:48:19 -0500, rumours say that Dan Sommers <[EMAIL PROTECTED]>
might have written:
[snip: snacktime posts code to count bits]
Seems to work, is there a better way to do this?
[Dan]
for c in range( 128 ):
even_odd = 0
print '%3d' % c,
while
On 21 Feb 2005 06:48:19 -0500, rumours say that Dan Sommers <[EMAIL PROTECTED]>
might have written:
[snip: snacktime posts code to count bits]
>> Seems to work, is there a better way to do this?
[Dan]
>for c in range( 128 ):
>even_odd = 0
>print '%3d' % c,
>while c:
>c &= c -
On Sun, 20 Feb 2005 20:56:52 -0800,
snacktime <[EMAIL PROTECTED]> wrote:
> I need to convert a generator expression to a list expression so it
> will work under python 2.3.
> I rewrote this:
> for c in range(128):
> even_odd = (sum(bool(c & 1< As this:
> for c in range(128):
> bo = [bool(c
snacktime wrote:
> I need to convert a generator expression to a list expression so it
> will work under python 2.3.
>
> I rewrote this:
>
> for c in range(128):
> even_odd = (sum(bool(c & 1<
> As this:
>
> for c in range(128):
> bo = [bool(c & 1< even_odd = sum(bo) & 1
>
>
> Seems to
snacktime wrote:
I need to convert a generator expression to a list expression so it
will work under python 2.3.
I rewrote this:
for c in range(128):
even_odd = (sum(bool(c & 1<
As this:
for c in range(128):
bo = [bool(c & 1<
Seems to work, is there a better way to do this?
If you want to keep
snacktime wrote:
I need to convert a generator expression to a list expression so it
will work under python 2.3.
I rewrote this:
for c in range(128):
even_odd = (sum(bool(c & 1<
As this:
for c in range(128):
bo = [bool(c & 1<
Seems to work, is there a better way to do this?
Well, if you were ha
13 matches
Mail list logo