Skip to content

Instantly share code, notes, and snippets.

@haowen-xu
Created April 29, 2019 08:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save haowen-xu/9bb1d34be1777f42afa03234e2f72682 to your computer and use it in GitHub Desktop.
Save haowen-xu/9bb1d34be1777f42afa03234e2f72682 to your computer and use it in GitHub Desktop.
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')
@zl
Copy link

zl commented Apr 29, 2019

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment