Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def float_bin(num):
- str_num = str(num)
- index_deci = str_num.find('.')
- float_num = float(str_num[(index_deci):])
- res_int_num = bin(int(num))
- res_float_num, i = ".", 0
- while bool(float_num):
- if i < 8:
- res = float_num*2
- res_float_num += str(int(res))
- str_res = str(res)
- index_deci = str_res.find('.')
- float_num = float(str_res[(index_deci):])
- i += 1
- else:
- break
- return res_int_num+res_float_num
- var = float_bin(2.77)
- print(var)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement