# How do I convert signed decimal to binary

1. Sep 30, 2009

### XodoX

1. Convert the following numbers to 32-bit two's complement binary numbers.

-22 , -100

Can someone explain this to me? I thought I just convert the +22, which is 10110 and add it to all the 1's. Like,

111111......10110 and positive would be 00000000.....10110. But that's not how it works.

2. Sep 30, 2009

### Staff: Mentor

You need to count backwards from 0000000 to 1111111 to 1111110, etc. Count with 0's for the negative numbers, not with 1's:

http://en.wikipedia.org/wiki/2s_complement

.

3. Sep 30, 2009

### XodoX

I dont knwo what you mean. I don't even shave the right numbers it seem.s

4. Sep 30, 2009

### Staff: Mentor

5. Sep 30, 2009

### XodoX

Yeah, I don't get it. I read it before I posted this thread.

6. Sep 30, 2009

### ridecar2

Right, here's how it's done.

1) You were right to convert the +ve value to binary to give 000...010110
2) Flip the bits (every 1 becomes a 0)

The bit that intrigued me was the adding 1 part but if we take 0 as an example and use 8 bits then:

0(dec) = 00000000(bin)
flip to give 11111111(dec)
If you don't add 1 then +0 and -0 are different so we add 1 and discard the carry to give 00000000.

-1 would then be 11111111
-2 becomes 11111110 and so on.

To show the usefulness of this let's have a look at 5 - 2:

We treat it as 5 + (-2) as you can in decimal:

00000101
11111110 +
-----------
00000011 (overfow set but ignored here)

So there you go, a whistlestop tour of 2's complement!

7. Sep 30, 2009

### XodoX

Thank you. So,

0110 1100 0001 0000 would be

0110 1100 0001 0001

I just haver seen an example where they did it totally differently.

8. Oct 1, 2009

### ridecar2

Not quite, to save any issues on here (and make sure I'm not doing any homework) I'll use an example I'm making up:

0011 0110 1001 0011
1100 1001 0110 1100 - Flipped
1100 1001 0110 1101 - With the 1 added, and that's the -ve value of 0011 0110 1001 0011 using 2's complement.

Last edited: Oct 1, 2009