Reputation: 603
I tried and this is what i've got so far:
10111.100 = 1.0111100 x 2 ^ 100
Giving 10111100 for the mantissa and 00000100 for the exponent, but i think i may have got it wrong.
Upvotes: 0
Views: 963
Reputation: 28826
23.5 is the same as 47 x 2^-1. 47 is binary 00101111. Now simply shift that right (and increment the exponent accordingly) until you get 1.0111100 and an exponent of 4 (binary 00000100). I assume you have some kind of bias for the exponent (probably 128) to cater for negative exponents, so add that.
In other words
23.5 = 47 * 2^-1 --> 00101111. exp -1
0010111.1 exp 0
001011.11 exp 1
00101.111 exp 2
0010.1111 exp 3
001.01111 exp 4 --> m=00101111 e=00000100
But normally, such value are normalized to set the top bit to 1:
1.01111000 exp 4.
And the exponent gets a bias, so negative values are turned into positive ones, say 128. Add 4 and you get:
e=10000100
The top mantissa (a.k.a. significand) bit is always 1, so it can be discarded, so now you have:
m=01111000 e=10000100
This is how I would store such a 16 bit floating binary point value.
Upvotes: 1