# Thread: Converting a number from decimal base to binary base (with the pencil)

1. ## Converting a number from decimal base to binary base (with the pencil)

Hi to all!
This is my first post so I feel like tot tell you that I studied programming in HighSchool and after two years of Mechanical University I found a part time job that choosed me to do some things.
I don't know C to much because I forgot most of it and actually I studyed it too little in the HighSchool (I didn't know I was wasting my time ) and I have some mounths to study it and do the job.

To get to the subject, I want to know the method to transform a decimal number in a binary number, but I want to know it like you write it on a piece of paper.
I kind of remember something and it's like this:

-for exemple to transform number 8810

--------------88/2
--------------88|44/2
---------------0|44|22/2
------------------0|22|11/2
---------------------0|10|5/2
------------------------1|4|2\2
--------------------------- 1|2|1
------------------------------0

I will explain what I did:
-first line I divided 88 by 2;
-44 of the second line is the result of 88 divided by 2;
-88 of the second line is the result of the multiplication of 44 with the same 2;
-0 of the third line is the result of the difference between 88 of the first line and 88 of the second line;
-44 of the second line I divided it by 2;
-forward I followed the same algoritm;

The binary number of 8810 is the red number read from right to left: 10110002 .

My problem is that I don't know if the algoritm is correct, so I ask for help.

2. well if you learn your base 2 numbers it is easier. Instead of 88/2 you can just find the closes number close to 88 in base 2. Then subtract that number from 88, then get whatever's left, and find the closest base 2 number close to that, until you get the decimal sequence in conjunction with the exponents of base 2.

Example

88
64 <--- 2^6 closest number to 88 in base 2
---
24
16<----2^4
---
8<-------2^3
8
----
0

Now decimal places 6, 4, and 3 are all 2s.

1011000

3. Originally Posted by indigo0086
Now decimal places 6, 5, and 3 are all 1s.

1011000
6, 5 and 3?

4. 6, 4, and three. Sorry for my dyslexia.

5. Now decimal places 6, 4, and 3 are all 2s.
All 2s?

 OK, really, though, the algorithm works, I think. This is the way I learned it, which is probably just the same, but worded a bit differently:
Code:
```0  88
0  44
0  22
1  11
1  5
0  2
1  1
0```
First, 88 divided by 2 is 44 remainder 0. 44 divided my 2 is 22 remainder 0, and so on down the line. (I would include them all, but all this coloring is really tedious.) Once you hit 0 on the right column, you are done, since 0 divided by 2 is 0 remainder 0, which you could just keep doing all day long if you keep going. You get your answer by writing the remainders in the opposite order you got them:
Code:
`1011000`
or 1011000 if the colors make your eyes hurt. (And let's face it; they do.)

6. "I am Error"

7. 128 64 32 16 8 4 2 1

88 >= 128 ? 0
88 >= 64 ? 1 (88-64 = 24)
24 >= 32 ? 0
24 >= 16 ? 1 (24 - 16 = 8)
8 >= 8 ? 1 (8 - 8 = 0)
0 >= 4 ? 0
0 >= 2 ? 0
0 >= 1 ? 0

0101 1000

8. Thank you indigo0086, I've got the algoritm.
Decrypt, your algoritm is exactly like my algoritm but I write more of it. It's simpler like yours.
simpleid, why is that a zero before all the number because all have not got that zero?

9. Square root algorithm is much more fun!

10. simpleid, why is that a zero before all the number because all have not got that zero?
He's padding the number out to 8 digits, or one byte.

0100 = 100.