- 5/2/2025
Struggling with converting decimal fractions to binary? In this fun, beginner-friendly tutorial, we dive into how to convert numbers like 45.8046875 to binary and back to decimal, step by step! Learn the multiplying-by-2 method, handle precision loss, and understand fractional binary representation. With real examples (0.126753, 0.84375), you?ll master this key computer science skill. Perfect for students, coders, or anyone curious about how computers store numbers. Subscribe for more tech tutorials, and let me know what you want to learn next! Visit [YourWebsiteLink] for more. #Binary #DecimalToBinary #ComputerScience #TechTutorials
Introduction to Decimal-Binary Conversion 00:00:00
Understanding Fractional Binary Numbers 00:00:15
Fractional Binary Representation Basics 00:01:00
Converting Decimal Fractions to Binary 00:04:06
Example: Converting 0.126753 to Binary 00:04:52
Precision Loss in Conversions 00:05:36
Example: Converting 0.84375 to Binary 00:09:57
Converting Binary Fractions to Decimal 00:14:22
Example: Converting Complex Number 45.8046875 00:16:48
Combining Whole and Fractional Parts 00:21:00
Conclusion and Verification 00:23:25
Outro and Community Engagement 00:24:16
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
Introduction to Decimal-Binary Conversion 00:00:00
Understanding Fractional Binary Numbers 00:00:15
Fractional Binary Representation Basics 00:01:00
Converting Decimal Fractions to Binary 00:04:06
Example: Converting 0.126753 to Binary 00:04:52
Precision Loss in Conversions 00:05:36
Example: Converting 0.84375 to Binary 00:09:57
Converting Binary Fractions to Decimal 00:14:22
Example: Converting Complex Number 45.8046875 00:16:48
Combining Whole and Fractional Parts 00:21:00
Conclusion and Verification 00:23:25
Outro and Community Engagement 00:24:16
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
Category
🤖
TechTranscript
00:01Hello there! Let's talk about how to convert decimal numbers with fractions into binary numbers with fractions and vice versa.
00:15So up to this point, if you've been watching my other videos, you probably know that you can easily convert a decimal number to binary and binary to decimal if the decimal and binary numbers are whole numbers.
00:28But in order to progress towards IEEE 754 representation, in other words, in order to eventually be able to represent binary numbers with fractions like floats or doubles in the machine, you have to start learning how to get the fraction part of a decimal number into binary.
00:47The way we're going to do it in this video, it's not actually going to be the final representation of how your machine stores floating point numbers, but it's an important step on the way there.
00:57Without this step, you probably wouldn't be able to do it.
00:59So what am I talking about? I'm just going to open up this notepad real fast and just show you that what I really mean is, suppose we have like a number 45 point blah, blah, blah, blah, blah, blah, right?
01:09So this is the whole part and this is the fractional part. Okay, no problem.
01:13Also, in binary, we have like a bunch of ones and zeros. This is a whole number, but we could put a decimal point and then just start doing more numbers after the decimal point in order to represent a fractional binary number.
01:27Okay, so let's see. We know, hopefully at this point, if you watch my other videos that, I don't know, I'm just going to put some random numbers here and then like some more random numbers there.
01:41And you know that the strength of each of these numbers is sort of like increasing by powers of two on the left side on the whole side.
01:49So this the strength of that first digit is one. The next digit has a strength of two and then four and then eight and then 16.
01:58Maybe I'll put the six up here and then 32. So three and two and then 64.
02:06And maybe I'll do another digit. I'll just put like a zero there. And then, you know, the leftmost most digit has a strength of 128.
02:14So basically, to figure out what the whole part means here, you're just taking a one or a zero for the actual binary number multiplied by its strength.
02:23So one times one is one. Add that to zero times two. Add that to one times four and zero times eight and one times 16 and so forth, right?
02:32So hopefully we know how to do that at this point. To do the same thing on the fractional side, maybe I won't put a decimal marker there.
02:39It's really the same deal, except as we go left, we were multiplying by two because the numbers or the digits should have more power, more strength.
02:49But as we go to the right past the decimal point, they should have less strength and we'll just divide them by two.
02:55So pretty much at this point, let's see, we'll have one half will be the strength of this digit right here. Whoops.
03:04One half. So the strength that that digit has is just one half. The strength that the next digit has is going to be one fourth.
03:15Remember, you multiply sorry, you divide by two each time. Whoops, I'm getting lost. Oh, man, I probably need to add some spaces because it's starting to get pretty ugly.
03:25So this digit has a strength of one half. This digit has a strength of one fourth.
03:30And then we'll just say that the next one has a strength of one eighth and so forth. We'll just keep dividing by two each time.
03:38Don't forget that. Don't make the mistake of saying one fourth or sorry, don't make the mistake of saying one half, one third, one fourth.
03:45Don't increase the denominator by one. You want to multiply or sorry, you want to divide by two each time.
03:51Or if you want to say the word multiplication, then you multiply by 0.5, I guess, if you want to.
03:59I'm just going to write one sixteenth and then just be done with the divisions.
04:03I hope you understand what I'm talking about. We're going to do some examples.
04:07Right now. OK, so let's calculate.
04:13Well, actually, let's just just just to just to emphasize, just to make sure everybody understands what we would do to convert such a number from binary to decimal would basically be, you know, compute the left side as as if it were a whole number.
04:27I want to put W for whole number and then separately convert the fractional part as if it were just, you know, zero point something and then just combine the two things when you're in decimal.
04:36And you'll do the same thing when converting a number from decimal to binary.
04:40You convert the whole part first, put that into ones and zeros, then convert the fact of the fractional part into a fractional binary part and then just combine them across the decimal point.
04:50So let's do an example. Let's start with converting zero point one, two, six, seven, five, three.
04:59I don't think that this number is going to resolve easily.
05:03It's kind of like a good lesson here.
05:05When you're converting between binary and decimal, there are always going to be some numbers in decimal that you can't represent in binary and vice versa.
05:14There are always going to be some numbers in binary that you can't represent in decimal.
05:19So it's not that decimal or binary or, you know, superior or inferior.
05:23I mean, all technology is pretty much running on binary, so it can't be that bad.
05:29But just keep that in mind.
05:31Some numbers that you type randomly are just never going to resolve.
05:35And you'll have to give up at some point and say, well, we're just going to call this a precision loss because we just we just have to give up, especially if you only have so many bits to put the fraction in.
05:45OK, so what am I going to do? What's the what's the basic algorithm here?
05:50There are lots of different ways to do it.
05:52The way that I'm going to show you is just multiplying by two.
05:56So if we take, you know, point one, two, six, seven, five, three, and we multiply it by two.
06:03We end up with, let's see, times two.
06:06Whoops. Hello. Oh, I got to do that.
06:08Times two.
06:10We're going to end up with a different number.
06:12If the number is equal to or greater than one, then we will say that we have achieved a number of one for the converted binary number.
06:22And if not, we'll say we have achieved a number of zero.
06:25If the number is one, we'll also subtract one from the, you know, the remaining number here in decimal.
06:30So in this case, the result we have is just what's going on.
06:34Oh, but I somehow turned on my annotator.
06:37OK. In this case, we just have, you know, this number right here.
06:43It's not greater than one or equal to one.
06:45So I'm just going to say this gave us a binary number of zero.
06:48And because it gave us a zero, we're not actually going to change it at all.
06:53We're not going to subtract one from it.
06:55We're just going to leave it as is.
06:57We will then multiply by two again.
07:00So I'm just going to say, do it one more time.
07:02We'll say this multiplied by two.
07:06And it's going to be this number.
07:09Again, it did not exceed or equal one.
07:13So the bit in that position is going to be a zero.
07:16And we'll just copy and carry it over just as is.
07:21Do it again.
07:22And we'll say.
07:25Multiply by two.
07:27Now we have a number that equals or exceeds one.
07:30So we've achieved a one in the binary position.
07:33So it's going to be a one here.
07:34Then we got to subtract one.
07:36So we're just going to be left with zero point zero one four zero two four and whatever.
07:41And then we just continue.
07:42Maybe I'll do it a couple more times, but I'm going to give up because I don't think that this number will translate completely.
07:48So I'm going to say multiply by two again, and it's going to give us a hang on a second here.
07:56What was that?
07:57That was one.
07:58Oh, I forgot to subtract one.
07:59So I got to subtract one and then I'm going to multiply by two.
08:04Now we get this number right there.
08:09This is not equal to or greater than one.
08:12So the bit is going to be zero.
08:14Then that means the remaining number is just going to be the same thing.
08:19We'll do another.
08:20Actually, let me let me clean the calculator for a second here.
08:23I'm going to select this whole thing and just paste that and I'm going to say multiply by two.
08:27That's going to be that new number.
08:30And I think you're starting to understand why I want to give up because we'll just be kind of doing this forever.
08:35This might end up being an irrational number in binary.
08:38I don't really know.
08:39I haven't gone that far, but it's definitely going to take a long time.
08:43So I'm going to give up and I'm just going to say, all right, the final binary number is going to be zero point zero zero one zero zero.
08:50And then just say maybe there's some more stuff at the end.
08:53We'll just call this a precision loss.
08:56You can see maybe I should do one more number, actually, because it it's kind of a mirror.
09:01There's like two zeros and then a one and then two zeros on the other side.
09:04Let me multiply this by two real fast just to show you without symmetry what would happen.
09:11So I'm going to multiply that by two and it's going to be this number right here.
09:17So that's going to be zero because it didn't exceed or meet one.
09:21And so the number we have left over is just that.
09:23OK, so now because there's no symmetry, you can see that the number is going to be point zero zero one zero zero zero.
09:30We go from top to bottom.
09:31We don't do any kind of reversal like you might do with whole number binary conversion.
09:36I don't know.
09:37Maybe it'll be zero for a long, long, long, long time and never or there'll probably be some ones in there.
09:42At least I don't know if it's ever going to resolve.
09:44You'll know you're finished when the leftover number here is a zero.
09:49So again, I'm just going to give up on this because I don't really know if it's going to work.
09:53Let's do a number that I know is going to resolve.
09:56I have this one prepared in advance.
09:59So let's do zero point eight four three seven five.
10:04OK, so how do we convert this again?
10:07Just multiply by two every single time you meet or exceed one.
10:13Then you'll say that we have a one in the binary number and then subtract one after that.
10:19And if not, we will say that we have a zero in the binary position and then we won't subtract one.
10:24OK, so that number multiplied by two is going to be point one six eight seven five.
10:29So that's definitely greater than or equal to one.
10:33I'm going to say we have a one in the binary position and then the next number is going to be just be zero point six eight seven four six eight seven five.
10:42OK, now we take that number six eight seven five.
10:45You could also just, you know, in your calculator, you could say minus one and then we'll multiply it by two to get the next bits.
10:53The number is going to be one point three seven five here and then it's greater than or equal to one.
11:00So it's going to be another one here.
11:02And then after we subtract one, it's going to be three seven five.
11:06No problem. OK, so let me just minus one here and then multiply by two to get to the next bit position.
11:14It's going to be zero point seven five. All right. So zero point seven five.
11:19That number is less than one. So we have a zero in that bit position.
11:23We also don't subtract anything because we had a zero in that bit position.
11:27Then we just like multiply by two again, multiply by two.
11:31Now we have one point five because that's greater than or equal to one.
11:36We have a one in that bits position. Then we subtract one.
11:40It's just going to be zero point five.
11:42That should be pretty easy, right?
11:43Because that's that sounds like there's a one in a bit and then it's just done after that.
11:47So I'm going to do minus one and then multiply by two again.
11:52Notice how that is exactly a one.
11:54So it's going to be one point oh, which means we have a one in the position because it is equal to or greater than one.
12:01And then, well, what we have left over is zero.
12:06Zero multiplied by two is going to be zero.
12:09So that means if we kept doing this forever, then all the numbers down here are just going to be zeros forever.
12:14And I said in another video, when you realize what's what what's going on with the zeros, like where are they?
12:21Are they on the left or the right?
12:23When you're converting a whole number from binary to decimal or decimal to binary, the zeros would be on the left side.
12:30So that's why we would reverse because if you just add infinity zeros on the left of a whole number, you're not changing the value.
12:37But if you added them to the right, you'd be increasing the value.
12:40When it comes to the fractions, the right side of the fraction won't change the number.
12:44For example, if we had, you know, one point and then some like random binary numbers, if we just kept adding zeros on the right side,
12:50that's not changing the value of the number because this is the fractional part.
12:53However, if we started adding numbers on the left side, then we would make the fractional part smaller and smaller and smaller.
13:00So that means the zeros have to be on the right side.
13:03And you can see here, the right side is the bottom.
13:06So that means we're going to take these numbers.
13:09I'll just put et cetera here, just so you can see, et cetera.
13:13That means we're going from top to bottom.
13:16So the final number is 0.11011.
13:20And then a bunch of zeros after that are just, you know, nothing.
13:23And that's the final answer.
13:24We now have 0.84375 is equal to binary that number.
13:32And we'll just say OB to indicate that the following is a binary number.
13:36Because again, you could have a decimal number and then have like a bunch of like ones and zeros in the fraction part, I guess.
13:44So to make sure that the reader understands what they're seeing, you'll say OB to indicate this is a binary number.
13:50On exams or quizzes, if you're out there doing this for an exam or a quiz, keep in mind, you probably want to talk to a professor to make sure that OB is supposed to be part of your answer.
14:02They might just want this.
14:04It depends.
14:05Anyway, so 0.11011.
14:09Okay, then let's convert it back again.
14:13Let's convert this number to the original decimal number there.
14:22Okay.
14:23So how can we do that?
14:24Pretty much just start adding the fractions up.
14:27So remember the first fraction that we see is going to be one half.
14:32One half.
14:34And the second fraction we see is going to be one fourth.
14:37We just keep multiplying one fourth, one half.
14:39Maybe I should write this in a notepad here.
14:41We'll see one half plus one fourth plus one eighth.
14:47And some of these bits aren't going to count.
14:49Like for instance, the one eighth, it's not going to count towards the fraction.
14:52But for me personally, if I forget to type one eighth, I'm probably going to accidentally use it for the next position.
14:59So I'm just going to type everything one at a time.
15:02So let's see.
15:03We have one, two, three, four, five, one, two, three, four.
15:06So I got to do one more plus one 32nd and then multiply by the bits.
15:11So say like, you know, one times that and then one times that and then zero times that to basically, you know, cancel it out.
15:20And then one times that and then one times that plug it all into the calculator.
15:26Let's see if I got that right.
15:300.84375.
15:32So that's how that's how you convert back from binary to decimal.
15:36Pretty easy.
15:37And then also, of course, when you're practicing this, you want to try with a bunch of different random numbers to start off with.
15:43You just want to be careful again.
15:45This process could take forever if you have like, you know, the wrong number that you start with.
15:51But I guess at least when we're converting from binary to decimal, it's going to end up resolving to something.
15:59It won't necessarily be something that you can't represent.
16:02But, you know, if you start up with a random number in decimal, there's a chance maybe it's not going to work with binary.
16:07OK, well, you have to give up and call it a precision loss.
16:12OK, so then now let's let's ask what if we had a complex number because we know how to do this now with just the fractional part.
16:21But what if we had a number that was a little bit more difficult?
16:26Let's say we have a wait a minute.
16:28You know, for you know, for 37, five.
16:36Oh, I think I just accidentally did a totally different number than I wanted to on my plan.
16:42Luckily, I got the right answer.
16:44OK.
16:45Anyway, what if we had a more complicated number?
16:49Let's see 804, six, eight, seven, five.
16:53OK, so 804, six, eight, seven, five.
16:56But with a 45 in front of that.
16:57Remember, we said before that this is the whole part and this is the fractional part.
17:01And you just want to do them separately and then combine them afterwards.
17:04So the whole part.
17:08And let's see, what is that going to be?
17:10I'm just going to say that this is not a video or whole number binary conversion.
17:15This is just dealing with fractions.
17:16Find my other videos if you want to know how to convert the whole part.
17:19But I'm going to say that 45 is just this number in binary.
17:24And you can double check real fast.
17:25You can say one plus here.
17:27Let's do it again.
17:28Let's do it just to be sure.
17:29One plus not a two because there's a zero there.
17:33And then we'll say four plus eight plus not a 16 because there's a zero there.
17:38And then plus 32 add that together.
17:42That's 45.
17:43So the whole number part is pretty easy if you already know how binary conversion.
17:46But now let's convert point zero eight zero point eight zero four.
17:53Whoops screenshot.
17:54No, thank you.
17:55Zero point eight oh four six, eight, seven, five.
17:58So I'm going to have to do this from scratch since this is a different number than I just worked with.
18:02We'll do that.
18:03Multiply it by two.
18:05And it's going to be this number.
18:07Six oh nine, three, seven, five.
18:11Is that really not the same number?
18:13Yeah, I guess I really just did a different number.
18:19Okay.
18:20So that means we're going to have a one in the binary position and the remaining fractional part is just going to be this.
18:26Whoops.
18:27Zero point that.
18:28So then we take that number and bring it down.
18:32Multiply it by two.
18:33Whoops.
18:34Not supposed to actually bring that part down.
18:36We'll bring it into the calculator.
18:38We'll multiply it by two.
18:40Actually, let me get that again and subtract one just to double check myself.
18:44It's always good to double check yourself.
18:45Then we'll multiply this by two.
18:47And then the number is going to be point one point two eight.
18:51So we have that.
18:53And then since it's either equal to or greater than one, it's going to be, you know, a one in the binary position.
19:00So zero point two, one, eight, seven, five is going to be the remainder there.
19:07So I'm going to do minus one and then times two to make sure the calculator agrees with me.
19:12Whoops.
19:13Two, one, eight, seven, five.
19:15Okay.
19:16Then I'll do a multiply by two to get the next number four, three, seven, five.
19:21And that's not equal to or greater than one.
19:25So we'll put a zero there and we won't subtract anything.
19:28So it's just going to be zero point four, three, seven, five.
19:31Again, then we'll multiply that by two to get the next number times two.
19:38It's going to be zero point eight, seven, five.
19:40So zero point eight, seven, five.
19:42Again, this is not one or greater.
19:44So we have zero in the binary position and we don't subtract anything.
19:48Zero point eight, seven, five.
19:50Multiply by two again times two.
19:54So it's going to be one point seventy five, one point seventy five.
19:58And then, of course, we'll have a one in the binary position and the leftover is going to be zero point seven five.
20:04So let me just go back to the calculator and I'll say minus one times two.
20:11It'll give us one point five.
20:13So one point five over here means we'll have a one in the binary position because it was equal to or greater than one.
20:19The leftover is going to be zero point five.
20:21Now, you know, we're about to finish because zero point five times two is just going to be one point zero, which will give us a one for the binary part.
20:30And then the remainder is going to be zero point zero.
20:33And then, you know, there's no need to multiply zero by two because it is forever going to just be zeros.
20:40Maybe I'll just write it out one more time to see, you know, zero zero zero.
20:43Right. Remember that.
20:44So that means, of course, the zeros are on the right side of the fractional part and on the left side is going to be zero point one one zero zero one one.
20:56And so I'll just put zero point one one zero zero one one one.
21:03And then now we just have to combine those two numbers.
21:07So maybe just I'll put something here indicating that this is the conversion of just that number like that.
21:15Now we'll combine both of those parts.
21:17Right. So 45 was this.
21:19So I'll say maybe therefore this big number right here, this complicated number is equal to combine this number for 45.
21:31And then I'll just put a decimal point and then I'll put the fractional part on the right side.
21:38And then let me just double check my work real fast.
21:40It should be one zero one one zero one one one.
21:46Wait, wait, wait, what?
21:47No, no. One zero one one zero one.
21:51And then one one zero zero one one one.
21:54OK, so that's it.
21:55We've converted a complicated decimal number into binary and we can do it in the reverse just using the same thing.
22:04You know, step one, convert this number into a whole number of decimal.
22:08And then step two, convert this number into a whole number.
22:11Sorry, a a just only fractional number for decimal by just getting the one half plus one fourth and so forth.
22:21And then just, you know, put them around a decimal point just for practice.
22:27OK, I'll go ahead and do it.
22:28Some of you are probably like, oh, why won't you do it?
22:30I'll do it.
22:31OK, so just only looking at the fractional part because this is not a video to convert whole numbers in binary and decimal.
22:39But just to convert the fractional part only, I'm going to do.
22:46Let's see.
22:47Say, whoops, whoops, whoops, whoops, whoops, whoops.
22:50Maybe I need to put that over there.
22:51OK.
22:52So starting with just this one right here, it's going to be one half plus one fourth plus not one eighth, not one sixteenth, a 32.
23:07132 plus one over 64 plus one over 128.
23:14And then if you look at the result, it should be 0.8046875.
23:22So it looks like we succeeded.
23:24OK, so now we know how to convert a decimal number with a fraction into a binary number with a fraction.
23:32And we also know how to convert a binary number with a fraction to a decimal number with a fraction.
23:39That feels like a long video.
23:40Let's see what it is after I cut this.
23:42Thank you so much for watching.
23:44I hope you learned a little bit of stuff and you had a little bit of fun.
23:47I will see you in the next video.
23:52Hey, everybody.
23:53Thanks for watching this video again from the bottom of my heart.
23:56I really appreciate it.
23:57I do hope you did learn something and have some fun.
23:59If you could do me a please, a small little favor, could you please subscribe and follow this channel or these videos or whatever it is you do on the current social media website that you're looking at right now?
24:11It would really mean the world to me and it'll help make more videos and grow this community.
24:16So we'll be able to do more videos, longer videos, better videos, or just I'll be able to keep making videos in general.
24:22So please do me a kindness and subscribe.
24:26You know, sometimes I'm sleeping in the middle of the night and I just wake up because I know somebody subscribed or followed.
24:31It just wakes me up and I get filled with joy.
24:33That's exactly what happens every single time.
24:35So you could do it as a nice favor to me or you could you could troll me if you want to just wake me up in the middle of the night.
24:40Just subscribe and then I'll just wake up.
24:43I promise that's what will happen.
24:44Also, 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.
24:54And 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.
25:03And if you have a suggestion for clarifications or errata or just future videos that you want to see, please leave a comment.
25:14Or if you just want to say, Hey, what's up? What's going on?
25:17You know, just send me a comment, whatever.
25:19I also wake up for those in the middle of the night.
25:21I get, I wake up in a cold sweat and I'm like, it would really, it really mean the world to me.
25:26I would really appreciate it.
25:27So again, thank you so much for watching this video and enjoy the cool music as, as I fade into the darkness, which is coming for us all.
25:38Thank you so much for watching.
26:08Bye.
26:09Bye.
26:38Bye.
26:39Bye.
27:08Bye.
27:09Bye.
27:38Bye.
28:08Bye.
28:38Bye.
28:39Bye.
Recommended
21:38
|
Up next
5:23
0:20