[Tutor] Floating Point Craziness

Steven D'Aprano steve at pearwood.info
Mon Jun 13 15:29:44 CEST 2011


Válas Péter wrote:
> 2011/6/12 Brett Ritter <swiftone at swiftone.org>
> 
>> Okay fine, so "1024" stored as a number only requires 10 bits (binary
>> digits) to store,
> 
> Actually, 11. :-)

I see your smiley, but actually more than that. Due to the way computers 
are designed, numbers are stored in fixed bundles of 8 bits making a 
byte. A single byte (8 bits) can store between 0 and 255. So to store 
1024, you need two bytes, or 16 bits, not 11.

In practice, that will usually be four bytes, 32 bits, or even eight.

And if you're using Python, where everything is an object, it will 
actually be fourteen bytes, or 112 bits:

 >>> sys.getsizeof(1024)
14




-- 
Steven


More information about the Tutor mailing list