Okay, so let's see where we are.
Integers, as well as strings, and everything else, are stored in memory 
as binary.
This is a given, because the architecture of the computer is binary.
You say 'the string representation of the integer is in base-10.'
Okay, well, python's representation of any object is different from what 
it's stored as,
which is binary.
So why do we care how it's stored?
 >>> a = 'a'
This is actually
 >>> ord(a)
97

a single byte that is stored in memory as
97 = 1100001.
Depending on the C implementation of a character.
But since it's a python string, and hence a python object, it also has 
methods tied to it.
The actual data that represents the character 'a' is somewhere in memory 
still stored as '1100001'.

If we want the binary representation of the character, we can't get to 
it directly.
So we get the value of the ord function (which is an integer that is 
stored as binary but represented as base-10 (which we also cannot access 
the binary for))
and we use some mathematical tricks to convert from the base-10 
representation to a binary one.
I know it's not stored as base-10.
This is perfectly clear to me.
However, in Python this is inconsequential.
I don't need to know the IEEE binary format for defining floats to know that
a = '.001' will work.
That number's in base-10, and it will be converted to base-2, because 
that's how the C implementation of float stores
its floats.  It may lose some precision here.

What I'm trying to get at is that in python, we see the numbers 
represented in specific bases.
 a = 0x2F
This is a base-16 number.  It's stored as binary by the C 
implementation, but we don't care because that doesn't matter at all
to us, and we can't access the binary anyway.

Basically, everything is stored as binary, but you don't say, given the code
astr = 'hello, how are you!'
'well yes, the string representation of astr is 'hello, how are you!' 
but  it's stored in memory as binary.'
I don't see why you do for integers.

I hope you don't see this as disrespectful.
I'm just not sure what you're getting at here.


You said:
 >no, he uses a mathematical conversion to go from a number represented 
in the internal format used by the C implementation (probably binary) to 
a list of '0' and '1' characters which represent binary bits.
No he doesn't.
He uses a mathematical conversion to go from a number represented in 
python as a base-10 number (which is represented by the C implementation 
as a binary number) to a list of '0' and '1' characters that represent 
binary bits.
He doesn't ever deal with the actual C representation of the binary 
number.  He deals with the python representation on top of that, which 
is decimal.

 >You have to make a distinction between the bit pattern used to 
represent the integer value, which is binary, and the character pattern 
used to represent the integer.
I do.
The bit pattern used to represent the integer value is binary in memory.
The way the integer is presented _to the programmer_ in python is 
decimal, which you term the 'character pattern'.
This distinction was the whole point of these e-mails,
because Carlos said that he could 'access the binary from memory' and 
put it into a list,
but what was really happening was that his program was taking the python 
'character pattern'
representation, which is in base-10, decimal, and using mathematical 
tricks to manipulate it back into the base-2 bit pattern.
His program doesn't deal with the internal representation of the integer 
as base-2, it deals with the external representation of base-10.
If it could access the internal representation, the program would be 
much more simple.
bitpattern = list(integer.bits) or something.

Hopefully ;)
-Luke


_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to