Skip to content

Instantly share code, notes, and snippets.

@whoozle
Created February 25, 2021 09:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save whoozle/ed2089469d79f01d10e2699ffa3c14f6 to your computer and use it in GitHub Desktop.
Save whoozle/ed2089469d79f01d10e2699ffa3c14f6 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
f = 0.3
e = 1
d = []
BITS = 32
#decompose
for i in range(BITS):
if f >= e:
d.append(1)
f -= e
else:
d.append(0)
e /= 2
print(''.join(map(str, d)))
#compose
e = 1
v = 0
for i in range(BITS):
if d[i]:
v += e
e /= 2
print(v)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment