[Math] How to convert from floating point binary to decimal in half precision(16 bits)

binaryfloating point

I'm trying to convert a 16 bit precision binary number to decimal format however I am completely failing to do so.

The binary I'm trying to convert is $0101011101010000$
My current method is:

Separation: $0|10101|1101010000$

Sign = 0

Mantissa = $1.1101010000$

Exponent = $21 – (2^4 – 1) = 6 $

Mantissa Denormalised = $1110101.0000$

This gives an answer of 117. Is this actually correct or am I making a mistake in my method?

Best Answer

You are right.

You can do that automatically with python and numpy :

import numpy as np
import struct
a=struct.pack("H",int("0101011101010000",2))
np.frombuffer(a, dtype =np.float16)[0]

and you get : 117.0