Convert decimal number to fixed point binary on Excel

Viewed 46

I have a column with decimal values (in this case, sine values, but it's irrelevant), for example: 0,024541229, and I need to convert it to a signed fixed point binary number, with 2 bits for the whole part (the -2 to +1 range is enougth, as sine values range from -1 to +1), and 6 bits for the fractional part.

Of course there will be loss of precision, as 1/(2^6) = 0,015625.

The Excel functions DEC2BIN() or BASE() doens't seem to be useful for that.

1 Answers

A fixed-point number is essentially an integer scaled by a fixed amount. In this case, if your real number is stored in A1, then the conversion to fixed-point would be:

=INT(A1*2^6)

This will scale the number to 1.570638656 and truncate it to 1.

Related