Created
April 29, 2019 08:54
-
-
Save haowen-xu/9bb1d34be1777f42afa03234e2f72682 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 real_to_hex(x, k=16): | |
assert(0 <= x < 1) | |
s = ['0.'] | |
for i in range(k): | |
y = int(x * 16) | |
s.append(hex(y)[2:]) | |
x = x * 16 - y | |
return ''.join(s).rstrip('0') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks