Converting Decimal to Binary
Computer Programming, Semester 1
If you’re like me who just messed around and was chatting on discord instead of paying attention on one of the more trickier parts of Computer Programming, this here is for you loves. Next time pay attention in class, but don’t worry, future graduate of Stanford/Harvard/Yale/Princeton is here to help you out
1 - Recognizing
Decimal numbers are represented by a ‘10’ supscript and binary numbers are represented by a ‘2’ subscript. Comprende? Awesome. Let’s work on some practice and you’re going to figure out which one is binary and which one is decimal without looking a blurs!
Extra Tip: Binary numbers are only represented by a sequence of 0’s and 1’s
- 54₁₀ Decimal
- 010110₂ Binary
- 011111₂ Binary
- 143₁₀ Decimal
- 31₁₀ Decimal
2 - Decimal → Binary
First we’re going to take a decimal number – 90₁₀ and we want to get it into a binayr form sequence of zeroes and one. First we’re going to figure out the squares of 2.
2⁰ → 1
2¹ → 2
2² → 4
2³ → 8
2⁴ → 16
2⁵ → 32
2⁶ → 64
2⁷ → 128
So first we’re going to find which exponetial power of two 90₁₀ falls in between. We can see clearly that it’s 2⁶ and 2⁷. So now we have to chose one of the numbers to subtract between, now we can’t choose 2⁷ simply because it’s too large but we can do 2⁶ .
90 - 64 = 26
Now, quick thing, whenever we used the power of something we have to mark it in the decimal sequence. they all start off with 0 since we didn’t use any of them to subtract from 90 just yet. But since we just did 64 which is 2⁶ , we put a 1 instead of a 0 in our rows of numbers in the place where 2⁶ ’ s 0 would usually be.
2⁰ → 0
2¹ → 0
2² → 0
2³ → 0
2⁴ → 0
2⁵ → 0
2⁶ → 1
2⁷ → 0
However we’re not done, we still have 26…so we have to find where 26 falls on our exponential columns. 26 is inbetween 16 and 32, and since 32 is too large we’re going to subtract 26 by 16 (2⁴)
26 - 16 = 10
Now we turn our 0 beside 2⁴ to a one since we used it to subtract from our number.
2⁰ → 0
2¹ → 0
2² → 0
2³ → 0
2⁴ → 1
2⁵ → 0
2⁶ → 1
2⁷ → 0
We still have 10 though… where does 10 fall in between and how do we solve it? Think for a moment before checking the blur and solve.
10 falls between 2³ and 2⁴ and since 16 is too large, we subtract 8 from 10.
10 - 8 = 2
Now we turn the 2³ from a 0 to a 1 since we used it in our equations
2⁰ → 0
2¹ → 0
2² → 0
2³ → 1
2⁴ → 1
2⁵ → 0
2⁶ → 1
2⁷ → 0
We still have one number left though! 2, where does 2 fall inbetween? Trick question, it doesn’t fall inbetween. It falls on top of a number, specifically 2¹.
2-2 = 0
We turn the 0 from beside 2¹ into a 1 because we used it in our equation.
2⁰ → 0
2¹ → 1
2² → 0
2³ → 1
2⁴ → 1
2⁵ → 0
2⁶ → 1
2⁷ → 0
Now how do we get our 0’s and 1’s sequence? We go from up to down. Starting with 2⁰ we list our 1’s and 0’s until we reach 2⁷.
01011010
3 - Solution
Our solution is: 90₁₀ = 01011010₂
4 - Practice
Practice converting decimal to binary with the following numbers ^^
- 54₁₀
- 200₁₀
- 49₁₀
- 23₁₀
- 31₁₀
Keep your ansewer and work in blurs and details if you wish to share and have me to check!!