A few questiosn about encoding

Antoon Pardon antoon.pardon at rece.vub.ac.be
Fri Jun 14 03:36:29 EDT 2013


Op 13-06-13 10:08, Νικόλαος Κούρας schreef:
> On 13/6/2013 10:58 πμ, Chris Angelico wrote:
>> On Thu, Jun 13, 2013 at 5:42 PM, �������� ������
>> <support at superhost.gr> wrote:
>>> On 13/6/2013 10:11 ��, Steven D'Aprano wrote:
>>>> No! That creates a string from 16474 in base two:
>>>> '0b100000001011010'
>>>
>>> I disagree here.
>>> 16474 is a number in base 10. Doing bin(16474) we get the binary
>>> representation of number 16474 and not a string.
>>> Why you say we receive a string while python presents a binary number?
>>
>> You can disagree all you like. Steven cited a simple point of fact,
>> one which can be verified in any Python interpreter. Nikos, you are
>> flat wrong here; bin(16474) creates a string.
>
> Indeed python embraced it in single quoting '0b100000001011010' and
> not as 0b100000001011010 which in fact makes it a string.
>
> But since bin(16474) seems to create a string rather than an expected
> number(at leat into my mind) then how do we get the binary
> representation of the number 16474 as a number?

You don't. You should remember that python (or any programming language)
doesn't print numbers. It always prints string representations of
numbers. It is just so that we are so used to the decimal representation
that we think of that representation as being the number.

Normally that is not a problem but it can cause confusion when you are
working with mulitple representations.

-- 
Antoon Pardon




More information about the Python-list mailing list