Skip to content

Instantly share code, notes, and snippets.

@jasonmc
Created September 13, 2011 19:24
Show Gist options
  • Save jasonmc/1214800 to your computer and use it in GitHub Desktop.
Save jasonmc/1214800 to your computer and use it in GitHub Desktop.
Calculating twos complement
dSize = 8
twosC = lambda x: (x ^ (2**dSize -1))+1
print "Twos complement of 11 is:", twosC(11), "(" + bin(twosC(11)) + ")"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment