integer to binary...

Grant Edwards grante at visi.com
Thu Jun 1 16:04:33 EDT 2006


On 2006-06-01, nicolasg at gmail.com <nicolasg at gmail.com> wrote:

>>>> does anyone know a module or something to convert numbers like integer
>>>> to binary format ?
>>>
>>> They _are_ in binary format.
>>>
>>>> for example I want to convert number 7 to 0111 so I can make
>>>> some bitwise operations...
>>>
>>> Just do it:
>>>
>>> >>> 7 & 3
>>> 3
>>> >>> 7 | 8
>>> 15
>>
> this is exactly what I need -> http://www.daniweb.com/code/snippet285.html

That's nice, but I don't register at web sites like that.

>> I know I can do that but I need to operate in every bit
>> separeted.

I still don't get what you want a binary string for.

I can see wanting a sequence (e.g. array) of boolean values,
but how are you going to do bitwise operations on a binary
string?

-- 
Grant Edwards                   grante             Yow!  .. I think I'd
                                  at               better go back to my DESK
                               visi.com            and toy with a few common
                                                   MISAPPREHENSIONS...



More information about the Python-list mailing list