Master IEEE 754 Floats: Binary to Decimal Guide

Hey there! Ready to crack the code on IEEE 754 floating-point numbers? In this video, I break down how to convert decimals to binary and back for 32-bit and 64-bit floats with clear, easy-to-follow steps. From scientific notation to biasing exponents, I’ve got you covered with examples (like 45.84375!). Perfect for computer science students, programmers, or anyone curious about how computers store fractions. Pause, rewind, and learn at your pace! Subscribe for more, check my other videos, and drop a comment with your thoughts!

Introduction to IEEE 754 00:00:00
Prerequisites for Understanding 00:01:03
Steps to Convert Decimal to IEEE 754 00:02:31
Bias and Exponent Explanation 00:03:17
32-bit Float Layout 00:04:09
Sign Bit and Fraction Bits 00:05:44
Example: Decimal to 32-bit Float 00:07:56
Converting 45.84375 to Binary 00:08:34
Scientific Notation for Binary 00:09:05
Biasing the Exponent 00:10:26
Placing Bits in Layout 00:11:17
Final 32-bit Float Representation 00:13:32
Example: IEEE 754 to Decimal 00:14:28
Extracting Sign, Exponent, Fraction 00:15:36
Unbiasing Exponent and Reconstructing 00:16:23
Converting Binary to Decimal 00:18:53
Introduction to 64-bit Floats 00:19:47
64-bit Float Layout and Bias 00:20:05
Example: 64-bit Float to Decimal 00:21:09
Processing 64-bit Float Bits 00:22:05
Reconstructing 64-bit Scientific Notation 00:23:26
Final Decimal Conversion for 64-bit 00:25:00
Conclusion and Recap 00:25:54
Call to Subscribe and Outro 00:26:36

Thanks for watching!

Find us on other social media here:

  • https://www.NeuralLantern.com/social

Please help support us!

  • Subscribing + Sharing on Social Media
  • Leaving a comment or suggestion
  • Subscribing to our Blog
  • Watching the main “pinned” video of this channel for offers and extras

Hey there! Let’s talk about IEEE 754 floating point numbers stored inside of your machine.

What the heck am I even talking about? Well, uh, there’s a standard called IEEE 754 which governs

how floating point numbers are stored inside of your computer on x8664 machines. So, you know,

of watching this video you probably already know how to convert binary back and forth you know

between binary and decimal and hopefully you understand how to do binary with fractions

if you don’t i have other videos i’ll talk about that in a second and you also understand

that in the machine there is like a slightly different format that’s my doggy slightly

different format for storing signed integers in the machine okay so floating point numbers have

an even different uh format that we have to follow and the hardware is designed that way

hardware is designed that way so before we can really benefit you’re all gonna

see how bad I spell okay before we can benefit from this video your prerequisite

knowledge should be that for starters you should be able to convert back and

forth between binary and decimal including numbers with fractions so if

if you don’t know how to do that yet this video is is not for you just yet you

should go check out my other videos I explain in other videos exactly how to

do that go to the other videos come back and then check this one out after you

know how to convert back and forth between binary and decimal with

fractions the second thing you should know how to do before watching this

video is convert binary numbers with fractions to scientific notation and

and back again. Meaning you should understand scientific notation and you should also understand

how to take a binary number with a fraction and convert it to scientific notation and then

convert it or deconvert it back to like regular form. Again, I have another video for this,

so if you don’t know how to do that yet, you should probably pause this video and then go

Let’s see. For converting from a regular number to IEEE floating point number in the machine using just binary alone is the following.

So I’m going to say basic steps. Step one, convert the decimal number to binary if needed.

And I say if needed because I don’t know, maybe you started with a binary number so you don’t actually need to convert it.

it but I’m just going to assume that you have a decimal number so you’re going to convert it to

binary first then convert the binary number to scientific notation I don’t know if convert is

the right word here because we’re not actually changing the value of the number we’re just

changing the representation so convert it to a scientific notation form maybe would be better

step three we’ll add a bias to the exponents of the scientific notation form what do I mean by

notation form. What do I mean by that? You know, if you have like a binary number and it’s in

scientific notation format, it’s going to look like this. I liked when I’m doing IEEE 754,

I like to keep the right side of the number in decimal. I’m sorry if this confuses you, but

it’s not really necessary to convert this to binary when we’re just trying to convert back

and forth between IEEE. So I always say two to the something power rather than one zero to the

something power because I want to stay in decimal. So I’ll say, you know, two to the seventh power,

right? What this means is that seven is the exponent and I have to bias the exponent before

I put it into the machine. So maybe it’s worth understanding or maybe copy pasting right now

that the bias for 32-bit floating point numbers, I should probably, I’ll paste the whole thing here.

Okay. So here’s like the format for a 32-bit floating point number. We’re good about this

number. We’re good about this just for a second. The bias for 32-bit floating

point number in IEEE 754 is 127. So that means I pretty much have to just take

the number 7 and bias it by adding 127 to it. After I’ve done that I can convert

the biased exponent to unsigned binary whole number. To an unsigned binary whole

number. So step four here is just regular decimal to binary conversion. So I would take, you know,

seven plus 127. The result of that, which I think is like 134, maybe we’ll just be converted into

binary and unsigned binary integer, not two’s compliment or anything like that. Then step five

is respect the layout. So I just, I just copy pasted the layout up above and the layout is this.

you can see that here let me see if I just maybe paste this down at the bottom

you can see that we actually have 32 bits here if I count them for you real

fast we’ve got one for the sign and then we’ve got I can never remember this I

think it’s eight for the exponent one two three four five six seven eight got

eight bits for the exponent that means I’ve already used nine of 32 bits so

that means I should have like 23 bits here so one two three four five six seven

11, 12, 13, 15, 16, 17, 18, 19, 20, 21, 22, 23, just to double check.

So we know what the sine bit is.

Actually, we don’t yet know in this video.

So in this video, the sine bit, it’s always going to be a zero if the number is positive

and a one if the number is negative.

So that’s the sine bit.

The biased exponent bits go there.

And then these Fs, those are just the fractional bits.

just the, you know, like the mantissa or the mantissa part of the fraction. So imagine if we

have a number like this, all I’m saying is we would copy paste those numbers right here.

Notice how I’m ignoring that first one dot something, because when you put binary in

scientific notation, the first number is always going to be a one. So it can be assumed. There’s

no point in storing it inside the machine. And then if you don’t have enough digits to

you will literally just pad with zeros on the right side because padding with zeros on the right side of a fraction

doesn’t actually change the value. One, two, three, four.

If I put the zeros on the left side of the fraction, it would make the fractional part smaller and smaller.

So that would be bad. I don’t want to change the value.

And this is the opposite of how you pad a whole number.

If I put numbers on the left side of a whole number part, I’m not changing the value.

But if I put numbers on the right side of a whole number part,

which in this case would be the biased exponent, then I would be changing the value.

So we wouldn’t want to do that.

changing the value so we wouldn’t want to do that. Anyway I’m going to remove this and just stick

with step five so let’s see 5a is place the sine bits step 5b is and I’m going to do an example

for you don’t worry place the exponent bits and then 5c is place the fraction bits everything

the first one dot from scientific notation form.

Again, because the first one is implied, it will never be a zero if you’ve done it correctly.

If you end up with a binary number that looks like this in scientific notation, then you’ve

done something wrong because the first number is supposed to be a one.

Okay, so we have those basic steps.

And now let’s do an example.

1, 2, 3 example. Let’s convert decimal to IEEE 754 32-bit float format.

AKA single precision floating point number. Double precision floating point number is 64-bit.

We’ll do an example for that at the very end of this, but I’m just going to stick with 32 and do

number 45.84375, just double checking, and then we’ll convert to binary. Again, this knowledge

is contained in a different video. So if you don’t know how to do this yet, you’ll need to go see my

other video. And so you can see it’s, you know, 45.84375 in binary is just going to be this.

I’ve padded it with two zeros to the left just because, I don’t know, I have a habit of wanting

wanting everything to look like it’s inside of 8-bit chunks.

You can see there’s 8 bits here.

But really, I can just remove those first two numbers.

It doesn’t matter.

Convert the number to binary.

Then, I have to convert the binary number to scientific notation.

I’m going to put maybe pseudo-scientific notation

because I’m not going to convert the right part

where it’s the exponent into binary.

I’m going to keep it in decimal.

Just to clarify again,

convert a binary number to scientific notation and you were actually going to publish it somewhere

or give it to someone, then you should convert the right side. It’s just that I’m not going to

because I don’t really need to convert the right side. I’m not interested in having the whole

number in scientific notation in binary. I’m just interested in what the fractional bits are and

then what the exponent is going to do. Like how many positions to the left or right is it actually

going to move the decimal point? And that’s just going to be the number five, five times to the

five you know five times to the left or to the right so I’m gonna go pseudo

scientific notation you pretty much you know as I covered in the different video

all we’re gonna be doing is just moving the decimal point over one two three

four five until there’s a one in the leading spot and then account for it by

saying times two to the fifth power to say the number is a lot bigger than it

looks so that’s that and let’s see if there are any trailing zeros that’s

Let’s see if there are any trailing zeros, that’s okay on the right side of the fraction.

They don’t actually matter.

You can also just delete them if you want.

Then we need to bias the exponents.

So how do we bias the exponent?

The exponent is just the number five.

That’s see, I was telling you like I don’t really care to convert it to binary because

I’m just going to bias it first and then after that I’ll buy it or I’ll convert it to binary.

So biasing it is just basically adding the bias.

just to make sure that it’s on this page and it’s easy to see.

So I’ll do that.

So in the 32-bit float layout, the bias is 127.

So I’m going to add 127 to 5.

The final number is going to be 132.

So that’s the biased exponent now.

Then I convert the biased exponent to binary.

And that’s going to be this.

10000100.

Then set up the layout so you don’t get confused.

This step is crucial.

Everyone always gets confused by the layout because like we’re human beings.

I can’t count 32 zeros that are all like in the same area and like, you know, and not

get confused every single time.

I mean, I guess I won’t get confused half the time, but that’s not good enough.

So step one is place the layout for yourself so it’s easier for you to place the bits.

place the bits and I wrote this at the top 8 bits and 23 bits just as a reminder double check

yourself 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 that’s 23 bits 1 2 3 4 1 2 3 4 that’s

8 bits we don’t need to remember that the sign bit is one bit for now it’s not too hard so now

let’s place it so the first thing to note is that this number was actually positive positive is

the negative sign there, but if it makes you feel better, we’ll just put a positive sign there just to clarify and be specific.

So because the number is positive, the sign bit is going to be zero. If it were negative, it would be one.

Then we will put the biased exponent bits. So we already converted up there. So I’m just going to copy paste it here.

We’re pretty lucky that the bits are just as big as the number of biased exponent bits that are available.

But suppose for the sake of argument that we had,

the sake of argument that we had just like you know this small number here for the biased exponent

what would you do with the remaining spaces you would just pad with zeros to the left

because remember in whole numbers in binary and decimal you pad to the left you’re not actually

changing the value you definitely would not want to pad to the right but you got to put

a bit in every position it’s got to be something so i’m just going to pad with zeros

then we take the fractional part from the scientifically notated form so that’s just

form so that’s just this right here notice how I’m copy pasting every bit

except for the one that starts the number I’m not going to do the one dot

part because that’s always assumed so we don’t need to store it it wouldn’t make

sense I’ll copy paste the fractional part and I’ll just stick it down there

and now we have a bunch of leftover bits that we need to fill out with the

fractional part you pad to the right not to the left so I’m just going to put

zeros to the right because that won’t change the value of the fractional part

Now we’ve got it. I’m just going to double check my work here.

Oh gosh, it’s too hard to read and then a bunch of zeros. Okay.

Then remove these spaces because now that you’ve done your layout,

you actually want to bear in mind that the machine doesn’t have spaces.

The machine is just, you know, a bunch of ones and zeros everywhere.

So I’m just going to carefully remove the two spaces.

And this is it.

for floating point representation of the number of the decimal number positive 45.84375

seems like a lot but it’s not too bad once you kind of get used to the format

and the bias and you already know the other steps of you know converting decimal to binary and back

again so let’s do another number let’s do it backwards so i’m going to open up a new tab here

example, IEEE 754 32-bit float 2 decimal.

Okay, so suppose we started with the following number.

Start with this number.

Oh my gosh, right?

Remember the layout.

So in the layout we have, use the layout.

Maybe I should copy paste the layout again one more time just to make sure that it’s

easy to see.

it’s easy to see. So I’m going to paste it up at the top and well, no, maybe I want this because

this is like a little bit better. I want that version. Okay. So 32 bits, a bias of 127. So

we’re going to use the layout. I’m just going to copy paste the original number and then add

spaces because I know, well, I guess I can copy paste the layout itself right above that number.

I know I need a space right there that’s the sine bit and then I need a space

after that and notice how the numbers all line up so there’s nothing missing

just to double-check yourself okay so I have the layout I know right away that

the number is going to be positive because the sine bit is zero sign is

positive okay so then I need to pull the biased exponent will be biased

the exponent bits only so I’m just going to copy paste those bits and then I’ll

pull out the fractional part first pull out the fractional part I’m going to

copy paste all those bits and maybe I’ll just say zero point those bits because

that’s what I originally grabbed and I can delete all the zeros on the right

side because again that won’t change the value of the fractional part so I’m

going to delete make sure you’re only deleting zeros though delete that now I

I need to unbias the biased exponents.

First, actually, I should, well, let’s convert the biased exponent to decimal.

A little easier.

I guess you don’t have to do that, but it’s a little easier for me.

Pull the biased exponent.

So this number is going to be 132, which I think is what we had last night.

Let me just double check that.

132.

Yeah.

132, yeah so the biased exponent that we pulled out is 132 then we unbiased the

biased exponent so just subtract the bias again in 32-bit format here the bias

is 127 so I’m going to subtract 127 instead of adding 127 so now I know the

real bias or sorry I know the real exponent is 5 then I can recreate the

I’ll put sudo here just because it’s not, you know, I’m not, I’m not converting binary for,

for the entire thing. So that means I can take the fractional part here and I can say it’s going to be

one dot the fractional part. Maybe I should remove that zero here to make it less.

I don’t know. Cause if I put a one there, it kind of feels like I’m saying the number is

that it’s one dot something.

I don’t like that I’m putting a zero there.

I’m just gonna erase it

because it’s really gonna end up being a one.

And if I say pull the fractional part

and I put a one there,

then it doesn’t it kind of sound like

I’m pulling the one from somewhere?

No, the one is implied.

Anyway, so now I can recreate the number

in pseudo scientific notation.

I can say times two to the something power.

We know that the exponent is five.

Again, it’s pseudo scientific notation

because if five we’re gonna do the complete,

complete, you know, true scientific notation. The right side should also be in binary, but I’m not

going to do it. I’m a little bit lazy because we don’t need that IEEE. So it’s going to be two to

the fifth power. Then if I undo the scientific notation, I’m really just going to take this

scientifically notated version and I’m going to say, well, I’m going to move the decimal point to

the right five times because that’s what the part on the right says. So I’m going to go one, two,

1, 2, 3, 4, 5, stick it there, remove the original decimal point, and then I can remove

the exponent part. So then let me just double check my work. 1, 0, 1, 1, 0, 1, 1, 1, 0, 1. Okay.

So we’ve got that now. Then all we have to do is convert this number from binary to decimal.

The final number here is just, you know, it’s going to be the same number that we worked with

number that we worked with previously so I’m just going to copy paste it there is

you know of course this video is not about converting back and forth from

binary to decimal with fractions check out my other video if you want to learn

how to do that but once we do that you know this number becomes that number

and and now we know how to convert back and forth between a decimal number and

for 32-bit floats in the machine.

No problem.

A lot of steps, but no problem once you understand them.

Okay, now let’s do an example

with 64-bit floating point numbers.

Honestly, this is not gonna be more difficult.

In 64-bit floats, the idea and the format and the steps,

it’s all gonna be the exact same thing.

It’s just that we have more bits

for the biased exponent and the fraction,

and then the bias itself will be a little bit higher.

So let me copy paste the format for you to see.

at for you to see. So in IEEE 64-bit floats, IEEE 64-bit float, well IEEE 754, 64-bit float,

you know we refer to these floats as doubles right double precision floating point numbers.

Notice how instead of 8 bits for the biased exponent we have 11 so we can represent a much

notice how for the uh the fraction part instead of having 23 bits we have 52 bits so we can also

represent much more precisely that’s really the only difference let’s uh oh sorry the other

difference is also that the bias is now equal to 1023 instead of 127 so what is that like

10 times larger of a number that we can represent or something like that so mostly we get more

If you don’t like it, sorry, it’s the way it is.

It’s in the hardware.

So let’s do an example for a 64-bit float for a double.

64-bit example.

Let’s say we started with the following number.

Inside of the machine.

Like we looked inside of the machine and we grabbed these bits.

And I’ll get rid of the spaces.

So we have like a giant, big, huge number.

We have like a giant big huge number.

We’re trying to figure out, you know, what is this number in decimal.

So I’m going to add spaces to respect the layout.

I’m going to just copy paste the layout right here.

I’m going to say respect the layout.

I’m going to paste it and then that helps me line everything up.

So I’m going to say the sine bit is the first bit and then I’ll put a space there so I know.

All right, the sine bit is a one.

That means it’s going to be a negative number.

The biased exponent bits are there.

The fractional bits are there.

bits are there so well first thing I can just do is say that the sine is going to be negative

because the sine bit is a one

and then I’ll pull the biased exponent bits which is going to be this number right here

should pull the fraction bits next. Fraction bits are just here I’m gonna

copy paste those here and then I can remove the zeros. Be very careful you’re

not removing any ones. So there was a lot of wasted bits there. That’s okay. I’ll

convert the biased exponent to decimal. So that’s going to be…

I think and I did not do that in my head.

I have an answer sheet.

Don’t worry.

I’m not that cool.

Then we’ll unbiased or de-bias unbiased the biased exponents by just subtracting the bias.

Remember in this 64 bit format, the bias is 1023.

So that means I got to take 1031 minus 1023 and that will be equal to 8.

Okay.

Okay, now we kind of have everything we need to sort of reconstruct the scientific notation part, right?

We have the fraction bits, that’s the most important part.

Oh, and then also the sine bits.

So I can say negative something.

It’s obviously going to be one dot something because even though the number is negative,

it will still always start with a one.

That rule doesn’t change.

Negative one dot something and I’ll just paste the, whoops, paste the fraction bits.

I think I did paste the right thing.

right thing so we paste the fraction bits and then we have to use the regular exponent the

unbiased exponent the non-biased exponent two times times two to the oops times two to the eighth power

now this is our number in scientific notation um

convert to scientific notation i’ll put p for pseudo scientific notation

and then now we have to convert to just regular format okay so I’m going to

copy paste this right here and if it’s 2 to the eighth power that means the real

number is going to be bigger than it looks in scientific notation even though

if you are very familiar with scientific notation you kind of already know that

it looks big but you know if we just if we’re only talking about the bits on the

1, 2, 3, 4, 5, 6, 7, 8.

Put the decimal point there.

Remove the original decimal point.

Now we no longer need 2 to the 8th power.

And again, just as a reminder, if it was 2 to the negative 8th power,

you would be moving the decimal point in the other direction.

So now we’ve got this number 111, 010101, 0101, 0101, 0101.

Then a 0.01.

Okay, so then convert to decimal.

doesn’t talk about how to convert back and forth from binary to decimal find my other videos but

basically uh it’s going to end up being six uh negative four six nine point two five

okay we now have done a quick practice starting with a giant number of bits and slowly converting

them to the real uh floating point number in decimal that uh that they represent i’m not going

going to do another number in the reverse direction because we already did that for 32 bits

and again with 64 bits the only real difference is just you have more exponent and fraction bits

and the bias is a higher number and that’s it so like all the other steps are just the same

I just wanted to show you one time with a 64-bit number in one direction but

I think at this point we’re good thank you so much for watching this video I hope you learned

had a little bit of fun. I’ll see you in the next video.

and grow this community so we’ll be able to do more videos, longer videos, better videos,

or just I’ll be able to keep making videos in general. So please do me a kindness and subscribe.

You know, sometimes I’m sleeping in the middle of the night and I just wake up because I know

somebody subscribed or followed. It just wakes me up and I get filled with joy. That’s exactly what

happens every single time. So you could do it as a nice favor to me or you could troll me if you

want to just wake me up in the middle of the night, just subscribe and then I’ll just wake up.

just wake up I promise that’s what will happen also if you look at the middle of

the screen right now you should see a QR code which you can scan in order to go

to the website which I think is also named somewhere at the bottom of this

video and it’ll take you to my main website where you can just kind of like

see all the videos I published and the services and tutorials and things that I

offer and all that good stuff and if you have a suggestion for clarifications or

or errata or just future videos that you want to see please leave a comment or if you just want to

say hey what’s up what’s going on you know just send me a comment whatever I also wake up for

those in the middle of the night I get I wake up in a cold sweat and I’m like it would really it

really mean the world to me I would really appreciate it so again thank you so much for

watching this video and um enjoy the cool music as as I fade into the darkness which is coming for us

Thank you.

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply