Decimal to Binary Conversion Help. :-(

Caporegime
Joined
12 Mar 2009
Posts
26,776
Hello there. Well, I've been introduced to Binary, Hexidecimal and Octal number systems and I'm very confused. My confusion begins at converting a Decimal base 10 number into a binary number. My tutor has shown me several examples and I still don't get it, it just hurts my head looking at the question and it's really frustrating not knowing where to begin. I've had a quick Google, and my tutor will e-mail me with some notes later on this evening. I'm going to fall behind if I can't get my head around converting and I just need someone to explain it to me very simply if possible. I know that this is probably a piece of cake for most of you guys, I'm not dull, I'm just **** at math.

Anyway, hopefully somebody will be able to give me a hand, cheers in advance, and no " Google Binary Conversion" posts please because they just aren't constructive and it isn't what I'm asking for.

:)
 
Your example is confusing me, if you gave me a number I wouldn't know how to put it into a binary form just by looking at yours. Where do you start when converting? What's the easiest method? And could you please describe the method that you've just demonstrated. I know I'm a pain in the ass but I'm just trying to understand your method. :(
 
(Just in case the previous post wasn't enough)

It might help to remember how decimal works:

The number 42 means 4*10 + 2*1
The number 342 means 3*100 + 4*10 + 2*1

Each digit is 10x more/less 'valuable' than the next, hence why its call decimal. So, if you want to convert from decimal to binary, the crude way to think of it is:

If the number is 42, find the largest power of 2 number smaller than it. So, start at 1, keep doubling until you get too big and go back one. So imagine it writen like this:

Code:
42:  32 16 8 4 2 1

Now put a one under the largest one:

Code:
42:  32 16 8 4 2 1
      1

Now subtract that number from it. 42-32 is 10

Code:
10:  32 16 8 4 2 1
      1

Now repeat putting a one under the largest one that is still smaller, and subtract again:

Code:
2:  32 16 8 4 2 1
     1    1

Finally this becomes:

Code:
0:  32 16 8 4 2 1
     1    1   1

And you have got to 0, so your done. Put zeros under the rest:

Code:
0:  32 16 8 4 2 1
     1  0 1 0 1 0

So the answer is: 101010

Did I make things better or worse? :)
 
Last edited:
Binary works by expressing numbers as sums of powers of 2. So – for any number up to 255 – you need to work out how to express a the number in question as a sum of 128 (2^7), 64 (2^6), 32 (2^5), all the way down to 1 (2^0).

So, for example, 87 can be expressed as 64 + 16 + 4 + 2 + 1.

For each of these terms, we write them out as powers of 2:

64 = 2^6 (6 bits from the right)
16 = 2^4 (4 bits from the right)
4 = 2^2 (2 bits from the right)
2 = 2^1 (1 bit from the right)
1 = 2^0 (0 bits from the right, i.e. the rightmost bit)

So to construct the binary representation of the number, we just set the corresponding bits to 1, and all the rest to 0:

87 (decimal) = 1010111 (binary)

Hope that helps!
 
Last edited:
I used the following method for exams:

Say you need to convert 99. If you could only make one binary digit high, what's the closest you can get to 99?

64: 1000000

What's the closest you can get to 35 (99 minus 64) if you could only make one binary digit high?

32: 0100000

What's the closest you can get to 3 (35 minus 32) if you could only make one binary digit high?

2: 0000010

What's the closest you can get to 1 (3 minus 2) if you could only make one binary digit high?

1: 0000001

Now do simple binary addition:

1000000
0100000
0000010
0000001

becomes 1100011

99 = 1100011

if you need it as a byte then just add a 0 onto it: 01100011
 
Last edited:
Thanks you lot. Caustic, that really, really helped, and I'm off to make a cup of tea, have a sit down and then try some sums of my own. That seems quite simple in the way that you explained it and my head isn't hurting so much now. :D
 
Back
Top Bottom