[Tutor] First realscript + Game of Life

Kent Johnson kent37 at tds.net
Sat Nov 11 13:44:56 CET 2006

Luke Paireepinart wrote:
> <snip binary function>
>> But probably (surely) my interpretation is wrong. Hehe
> Ah, well, it's just the terminology you were using was a bit misleading.
> You say
> ' Hey Rooy, so its possible to copy binary numbers from memory?'
> All his function does is converts an integer (that's in memory, yes) 
> into a binary number.
> It doesn't copy the binary bit arrangement directly from memory.  It 
> uses mathematical operations on an integer in base-10, that it gets from 
> the binary in memory, to convert it to base-2.
> You could do the same for 16, or 32, or 64, or base 256 numbers if you 
> wanted to.
> The point I'm trying to make is that it's not extracting the actual bits 
> from the memory location or anything like that.
> It's just converting bases.  It doesn't matter that the number is stored 
> as binary cause to Python it's an integer.
> Think of it like this.
> This is what's happening
> Memory       Python     Binary_function
> [ 0000001] ->  1     ->    [0000001]
> It's not going from here
> Memory        Python
> [0000100] ->    4
> To here...
> Memory        Python
> [0000100] -> [0000100]
> Do you see what I mean?
> Python still sees the memory location as an integer,
> so it still stores the value (within python) in base-10, not in base-2.
> So even though the memory location has the actual bits, we can't access 
> them.

I think you are a bit confused here.

It's important to make a distinction between the way a number is 
actually stored in the computer and the string that is created when a 
number is printed.

Most computers store integers as binary numbers. So the number 21 for 
example will be stored as the bit pattern 00010100. In order to print 
this number, Python converts it to a string containing the two 
characters '2' and '1' (which are themselves stored as the bit patterns 
00110010 and 00110001) and outputs those characters to the console. So 
now we have two representations, the binary number stored in the 
computer memory and the string representation of the base 10 
representation of the number.

There are lots of other ways to represent the same number. What Carlos 
wants is the string representation of the binary representation of the 
number. This is confusing to talk about because the number is already 
stored in binary. The module he showed generates this representation.


> We can only get access to the python base-10 value.
> But it's fairly trivial to convert this integer into a binary list.
> It _is_ going through 2 conversions, though, the binary isn't directly 
> accessed, as I got the impression you thought.
> ' I had the impression that this could be done, but obviously it is too 
> much for me. This way is going to be faster than the hack that I tried 
> before, right? Thanks for the  module : )'
> I didn't see the hack you did before, so I don't know.
> But what he sent was a function, not a module.
> A module is quite a bit more of a complicated beastie than a function is.
> the wikipedia definition goes something like this:
> 'a *module* is a software entity that groups a set of (typically 
> cohesive <http://en.wikipedia.org/wiki/Cohesion_%28computer_science%29>) 
> subprograms <http://en.wikipedia.org/wiki/Subprogram> and data 
> structures <http://en.wikipedia.org/wiki/Data_structure>. Modules are 
> units that can be compiled <http://en.wikipedia.org/wiki/Compiler> 
> separately, which makes them reusable and allows multiple programmers to 
> work on different modules simultaneously. Modules also promote 
> modularity <http://en.wikipedia.org/wiki/Modularity_%28programming%29> 
> and encapsulation (i.e. information hiding 
> <http://en.wikipedia.org/wiki/Information_hiding>), both of which can 
> make complex programs easier to understand.'
> Not sure what exactly a module is (I get it confused with packages) in 
> Python.
> Perhaps someone can help here?
>>> 89+11 = 100, which is longer than the list.
>> Thanks Luke.
> Sure, glad to help  :-]
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor

More information about the Tutor mailing list