How do I convert signed decimal to binary

In summary, to convert a number to 32-bit two's complement binary, you need to count backwards from 0000000 to 1111111 to 1111110, etc. and add 1 to the answer.
  • #1
XodoX
203
0
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.
 
Physics news on Phys.org
  • #2
XodoX said:
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.

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
I don't knwo what you mean. I don't even shave the right numbers it seem.s
 
  • #4
XodoX said:
I don't knwo what you mean. I don't even shave the right numbers it seem.s

Did you read the wiki link?
 
  • #5
Yeah, I don't get it. I read it before I posted this thread.
 
  • #6
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)
3) add 1 to the answer.

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
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
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:

1. What is the process for converting a signed decimal to binary?

The process for converting a signed decimal to binary involves several steps. First, determine if the decimal number is positive or negative. Next, convert the absolute value of the decimal number to binary using the standard method. Then, add a sign bit of 0 for positive numbers and 1 for negative numbers. Finally, if necessary, perform a two's complement to get the final binary representation.

2. How do I know when to use a sign bit for a signed decimal number?

A sign bit is used for signed decimal numbers to indicate whether the number is positive or negative. If the decimal number is positive, the sign bit will be 0, and if the number is negative, the sign bit will be 1. This is important in converting to binary because it determines the placement of the sign bit in the final binary representation.

3. What is the standard method for converting a decimal number to binary?

The standard method for converting a decimal number to binary is to repeatedly divide the decimal number by 2 and write down the remainder. The binary representation is the binary equivalent of the remainders read from bottom to top. For example, to convert the decimal number 10 to binary, we would divide 10 by 2 and get a remainder of 0. Then, we would divide the quotient (5) by 2 and get a remainder of 1. Continuing this process, we would get the binary representation of 1010.

4. What is a two's complement and when is it used in converting a signed decimal to binary?

A two's complement is a method of representing negative numbers in binary form. It is used in converting a signed decimal to binary when the decimal number is negative. In this method, the binary representation of the absolute value of the negative number is found, and then all bits are flipped (0 becomes 1 and 1 becomes 0). Finally, 1 is added to the result. This results in the binary equivalent of the negative number.

5. Are there any shortcuts or tricks for converting a signed decimal to binary?

While there are no official shortcuts or tricks for converting a signed decimal to binary, there are some methods that can make the process easier. For example, if the decimal number is small, you can simply memorize the binary equivalents of those numbers. Additionally, using a calculator or an online converter can be helpful for larger or more complex numbers.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
2
Views
4K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
5
Views
1K
Replies
4
Views
821
  • Engineering and Comp Sci Homework Help
Replies
10
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
602
  • Engineering and Comp Sci Homework Help
Replies
5
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
1K
Back
Top