Skip to content

Instantly share code, notes, and snippets.

@whoozle
Created Feb 25, 2021
Embed
What would you like to do?
#!/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