Created
November 23, 2016 18:11
-
-
Save hbradio/232ea5b1d3a3d0db731d44a7e948f807 to your computer and use it in GitHub Desktop.
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
def twos_compl(val): | |
lsb = 1.0/2**15 | |
if (val < -1.0) or (val > 1.0-lsb): | |
raise ValueError("Out of range") | |
if (val > 0): | |
return np.binary_repr(int(val/lsb),16) | |
else: | |
return np.binary_repr(int(2**15 - (1.0 + val)/lsb), 16) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment