Advertisement
jabela

Denary to Twos complement

Aug 24th, 2017
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.22 KB | None | 0 0
  1. number = int(input("Enter decimal number"))
  2. bina = bin(((1 << 8) - 1) & number)
  3. if len(bina)!=8:
  4.     binc = ("0"*(10-len(bina))+bina[2::])
  5.     print("Twos Complement:",binc)
  6. else:
  7.     print("Twos Complement:",bina[2::])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement