binary numbers

Roel Schroeven rschroev_nospam_ml at fastmail.fm
Wed Oct 6 11:05:06 CEST 2004


Brad Tilley wrote:

> Darren Kirby wrote:
> 
>> quoth the Larry Bates:
>>
>>> Integers are stored in memory as binary.
>>>
>>> x=5
>>>
>>> stores 5 in x in binary form.
>>
>>>>> x=5
>>>>> x
>>
>> 5
>>
>>
>>  I think our friend is looking for a module or function that turns 5 
>> into 101 (or perhaps 00000101)
>>
> 
> Thanks, this is what I need.

Are you sure? I mean, are you really really sure? REG_BINARY indeed 
expects data in binary form, but that does not mean that you should 
convert it to a string of 0's and 1's. It means that it can take any 
series of bytes, and doesn't care what is in those bytes.

The struct module approach as explained by Max M sounds like a much 
better idea in your case. Even better to use REG_DWORD instead of 
REG_BINARY if that's possible for you.

-- 
"Codito ergo sum"
Roel Schroeven



More information about the Python-list mailing list