-1

I need to convert negative number to binary in python. How can I do it ?

EDIT: I need to use twos complement

De Novo
  • 7,120
  • 1
  • 23
  • 39
  • Can you give us an example of what you are looking for? Eg. should 255 be `-11111111` or be the 2s complement negative of a 1 byte integer? – Martijn Pieters Apr 01 '18 at 09:45

1 Answers1

0
bin(-2)
#'-0b10'

Use the built in binfunction to get a binary representation.

De Novo
  • 7,120
  • 1
  • 23
  • 39