help in obtaining binary equivalent of a decimal number in python

Chris Angelico rosuav at gmail.com
Thu May 23 07:37:30 EDT 2013


On Thu, May 23, 2013 at 9:30 PM,  <lokeshkoppaka at gmail.com> wrote:
> i need to get 32 bit binary equivalent of a decimal and need to change the 0's to 1's and 1's to 0's
> For Example
> if the input is 2
> Output should be:
> the 32bit equivalent of 2 :0000 0000 0000 0000 0000 0000 0000 0010
> and the 1's compliment is:1111 1111 1111 1111 1111 1111 1111 1101
>
>
>
> is there any pre-defined function to get the above results in python??

You're asking for bitwise negation. Now that you know the keyword(s)
to look for, you should be able to figure out the rest with a few
quick docs and/or web searches.

ChrisA



More information about the Python-list mailing list