Created
September 13, 2011 19:24
-
-
Save jasonmc/1214800 to your computer and use it in GitHub Desktop.
Calculating twos complement
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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