Last active
January 9, 2017 11:10
-
-
Save plopp/a5c1388cc503b2f0eb54fd5f44a9cded to your computer and use it in GitHub Desktop.
This file contains 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
def twosComplement(val, nbits): | |
n = (2**nbits) | |
if(val > (n/2-1)): | |
return val-n | |
else: | |
return val | |
print twosComplement(64123,16) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment