English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

3 answers

Have a read here, it helped me: http://www.daniweb.com/code/snippet109.html

2007-02-13 22:21:33 · answer #1 · answered by D M L 4 · 0 0

Not sure if this is the answer you are looking for but,

Decimal to Binary

Works to the power of 2 starting with 1 on the far right and ending in 128 on your left, co if you have a decimal of 87 it would look something like this.

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

That's the table filled from right to left with multiples of "2"

Then choose the highest multiple of "2" you can subtract from your decimal which in this case is 87

So your table will now start to look like this

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

now you subtract the value from your number so 87-64 is 23

so you now have

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

then same again 23-16 is 7

then it would be 7-4 is 3, 3-2 is 1 and 1-1 is 0

So your table should now look like this

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

Making your Binary number 01010111

and To answer your question all you do is reverse that adding the numbers from Left to Right this time so it would be

01010111 = 64 + 16 + 4 + 2 + 1 = 87

and that's how you get Binary to Decimal Conversion

2007-02-13 23:00:48 · answer #2 · answered by dev12342002 3 · 0 1

How are you reading this binary number? If it's a char array, simply do an sscanf on it to rip the number out, and set the read flag as binary, which I believe is %b, and print with either %d or %i which are the same thing.

Good luck!

2007-02-13 23:17:49 · answer #3 · answered by Anonymous · 0 0

fedest.com, questions and answers