16th decimal to integer code example

Example 1: converting float to binary 16

import struct
#################### bin32 ################################
# import bitstring
# f1 = bitstring.BitArray(float=0.456789, length=32)
# # f1 = bitstring.BitArray(float=0.456789, length=16)
# print(f1.bin)
# print("0011011101001111")
#################### bin32 ################################

def convertFloatToBin16(x):
    k = struct.pack('>e', x)
    z = ''.join(format(i, '08b') for i in k)
    return str(z)

print(convertFloatToBin16(0.9945678))

Example 2: Converting the hexadecimal number 29.48 to decimal gives you 2/2 41.125 41.8125 41.25 41.28125

Converting the hexadecimal number 29.48 to decimal gives you




41.125



41.8125



41.25



41.28125

Tags:

C Example