Trusted answers to developer questions

Educative Answers Team

A single-precision binary float is represented using 32-bits. These bits are divided into three sections to represent the sign, exponent, and fractional parts of a decimal number (according to the IEEE 754 standard).

The fractional part is first converted into a decimal by summing all the $2^{-n}$s (where $n$ is the position of a bit in the fractional part that has a $1$). For example, if the 23-bit fractional part has a $1$ at bit number 2 and 3:

Its decimal equivalent would be:

$2^{-2} + 2^{-3} = 1/4 + 1/8 = 0.375$

Applying the following formula will convert the whole 32-bit binary number into a decimal,

$(-1)^s\times(1+$ **Fraction**$)\times2^{exp-127}$

,where $s$ is the sign-bit, **Fraction** is the value that has been computed above as an example, and $exp$ is the numerical value, in base 10, of the 8-bits reserved for the exponent.

$s=1$

**Fraction** $=2^{-1}=0.5$

$exp=2^0+2^1+2^7=1+2+128=131$

Substitute the values in the formula to obtain the final answer:

* Answer* $=(-1)^1\times(1+0.5)\times2^{131-127}=-1.5\times2^4=-24.0$

RELATED TAGS

floating point

convert

base 10

bits

fraction

Copyright ©2022 Educative, Inc. All rights reserved

RELATED COURSES

View all Courses

Keep Exploring

Related Courses