代码拉取完成,页面将自动刷新
def float_bin(my_number, places = 3):
my_whole, my_dec = str(my_number).split(".")
my_whole = int(my_whole)
res = (str(bin(my_whole))+".").replace('0b','')
for x in range(places):
my_dec = str('0.')+str(my_dec)
temp = '%1.20f' %(float(my_dec)*2)
my_whole, my_dec = temp.split(".")
res += my_whole
return res
def IEEE754(n) :
sign = 0
if n < 0 :
sign = 1
n = n * (-1)
p = 30
dec = float_bin (n, places = p)
dotPlace = dec.find('.')
onePlace = dec.find('1')
if onePlace > dotPlace:
dec = dec.replace(".","")
onePlace -= 1
dotPlace -= 1
elif onePlace < dotPlace:
dec = dec.replace(".","")
dotPlace -= 1
mantissa = dec[onePlace+1:]
exponent = dotPlace - onePlace
exponent_bits = exponent + 127
exponent_bits = bin(exponent_bits).replace("0b",'')
mantissa = mantissa[0:23]
final = str(sign) + exponent_bits.zfill(8) + mantissa
hstr = '0x%0*X' %((len(final) + 3) // 4, int(final, 2))
return (hstr, final)
print (IEEE754(float(input("请输入你想转化的数值"))))
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。