From: Ulrich Eckhardt on 7 Jun 2010 07:57 Peter Otten wrote: > Ulrich Eckhardt wrote: >> Says Python: >> >>>>> bin(192) >> '0x11000000' > > Hmm, if that's what /your/ Python says, here's mine to counter: > >>>> bin(192) > '0_totally_faked_binary_00000011' Argh! Of course one of my Pythons says '0b11000000' and not what I mistyped above.... =( Uli *goes and hides under a stone* -- Sator Laser GmbH Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932
From: superpollo on 7 Jun 2010 08:07 Ulrich Eckhardt ha scritto: > Peter Otten wrote: >> Ulrich Eckhardt wrote: >>> Says Python: >>> >>>>>> bin(192) >>> '0x11000000' >> Hmm, if that's what /your/ Python says, here's mine to counter: >> >>>>> bin(192) >> '0_totally_faked_binary_00000011' > > Argh! Of course one of my Pythons says '0b11000000' and not what I mistyped > above.... =( mine goes like this: >>> bin(192) Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'bin' is not defined
From: Ulrich Eckhardt on 7 Jun 2010 08:54 superpollo wrote: > mine goes like this: > > >>> bin(192) > Traceback (most recent call last): > File "<stdin>", line 1, in <module> > NameError: name 'bin' is not defined Yep, one of mine, too. The "bin" function was new in 2.6, as were binary number literals ("0b1100"). Uli -- Sator Laser GmbH Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932
From: Grant Edwards on 7 Jun 2010 10:16 On 2010-06-07, Richard Thomas <chardster(a)gmail.com> wrote: > You're reading those bits backwards. You want to read the most > significant bit of each byte first... Can you explain the reasoning behind that assertion? -- Grant Edwards grant.b.edwards Yow! I can't decide which at WRONG TURN to make first!! gmail.com I wonder if BOB GUCCIONE has these problems!
From: Terry Reedy on 7 Jun 2010 14:58 On 6/7/2010 6:20 AM, Ulrich Eckhardt wrote: > Ulrich Eckhardt wrote: >> data = f.read() >> for byte in data: >> for i in range(8): >> bit = 2**i& byte >> ... > > Correction: Of course you have to use ord() to get from the single-element > string ("byte" above) to its integral value first. In Py3 (OP did not specify), a binary file is read as bytes, which is a sequence of ints, and one would have to not use ord() ;=) tjr
First
|
Prev
|
Next
|
Last
Pages: 1 2 3 4 Prev: Non Sequitur: Re: Python Forum Next: os.path.normpath question |