From: Ulrich Eckhardt on
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
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
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
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
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