DEV Community

Nozibul Islam
Nozibul Islam

Posted on

How Do Floating Point Numbers Work?

We often use floating-point numbers in programming, but have we ever thought about how they actually work?

Let’s take a look at the following binary number: 1111.1101

How is it converted to a decimal number?

πŸ”Ή Integer Part (1111)

Binary value: (1Γ—8) + (1Γ—4) + (1Γ—2) + (1Γ—1) = 15

πŸ”Ή Fractional Part (.1101)

Binary value: (1Γ—1/2) + (1Γ—1/4) + (0Γ—1/8) + (1Γ—1/16) = 0.8125

Final Conversion:

1111.1101 (Binary) = 15.8125 (Decimal)

Top comments (2)

Collapse
 
dorinandreidragan profile image
dorinandreidragan

short and sweet πŸ‘

Collapse
 
nozibul_islam_113b1d5334f profile image
Nozibul Islam

thanks