Sinisterly
[Tutorial] Decimal to Binary - Printable Version

+- Sinisterly (https://sinister.li)
+-- Forum: Coding (https://sinister.li/Forum-Coding)
+--- Forum: Coding (https://sinister.li/Forum-Coding--71)
+--- Thread: [Tutorial] Decimal to Binary (/Thread-Tutorial-Decimal-to-Binary)



[Tutorial] Decimal to Binary - amando96 - 08-19-2011

I've seen many tutorials online, and most are over complicated, even the way they teach this at school is over complicated for something you can do in your head in 5 seconds.

We are used to dealing with the decimal system, 10 characters:
0, 1, 2, 3, 4, 5, 6, 7, 8, 9

Binary only uses two characters:
0, 1

Lets start converting, let's pick the Decimal number 43.

Then we make something like this to help with the conversion(when you're pro you can just imagine it in your head):

128 | 64 | 32 | 16 | 8 | 4 | 2 | 1

Why these numbers?
- You can create ANY number you want(up to 256) by adding any of these, want 10? add 8 + 2, want 5? add 4 + 1.

So, lets start from the left side.
- Is 43 bigger or equal to 128? No, so we skip to the next number and place a 0 in place of 128, table now looks like this:
Code:
128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 0


- Is 43 bigger or equal to 64? No, so again, we skip to the next number and place a 0 in place of 64, table now looks like this:
Code:
128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 0 | 0


- Is 43 bigger or equal to 32? Yes, so we do 43 - 32 = 11, and put a 1 under 32.
Code:
128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 0 | 0 | 1


Is 11 bigger or equal to 16? No, so 0 goes under 16.
Code:
128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 0 | 0 | 1 | 0


Is 11 bigger or equal to 8? Yes, so 11 - 8 = 3 and 1 goes under 8.
Code:
128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 0 | 0 | 1 | 0 | 1


Is 3 bigger or equal to 4? No, so 0 goes under 4.
Code:
128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 0 | 0 | 1 | 0 | 1 | 0


Is 3 bigger or equal to 2? Yes, so 3 - 2 = 1 and 1 goes under 2.
Code:
128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 0 | 0 | 1 | 0 | 1 | 0 | 1


Is 1 bigger or equal to 1? Yes, 1 goes under 1.
Code:
128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 0 | 0 | 1 | 0 | 1 | 0 | 1 | 1


So there you go, 43 is 00101011 in binary, how can we check if this is true?
- Add all the numbers that have a 1 under them.

1 + 2 + 8 + 32 = 43, correct Smile

Now do this number on your own: 78
Spoiler: Answer
01001110 Congrats if you got this! If not, don't worry, you'll get there.


Hope this tutorial was helpful, I searched a little and couldn't find another one so i decided to post it, also not sure if the section is the most suited.




RE: [Tutorial] Decimal to Binary - 1llusion - 08-21-2011

Wow this is awesome!!! I did binary myself, but in a different, more complicated way. Thank you for sharing!



RE: [Tutorial] Decimal to Binary - Jacob - 08-23-2011

(08-21-2011, 02:10 AM)1llusion Wrote: Wow this is awesome!!! I did binary myself, but in a different, more complicated way. Thank you for sharing!

im guessing your way was the dividing, mod, div, bin string reverse input method?o:


RE: [Tutorial] Decimal to Binary - Solixious - 08-25-2011

Its a great tutorial.. Kind of shortcut method when we get use to it..