2

What is the binary form of -10? How it is calculated?

4
  • 2
    Please retag this as homework if appropriate. I'd do it but Neil butterworth will call my mom.
    – 3Dave
    Jan 29, 2010 at 5:20
  • -10 is binary (equals -2 in decimal). "-" is not restricted to just decimal numbers. ;)
    – mbeckish
    Jan 29, 2010 at 5:35
  • As you might be able to tell from some of these answers, the representation depends on multiple factors, such as what the processor architecture is or which protocol or file format the number appears in. Not all platforms have the same byte ordering, and not all use two's compliment (though many do)
    – Jacob
    Jan 29, 2010 at 6:15
  • The question is not fully stated. There is no "the" binary form of -10, even if we ignore endian-ness (which we should, because the question, as stated, is not about how the number is stored in memory). Jan 29, 2010 at 6:40

4 Answers 4

7

To convert -10 (decimal) to binary:

Repeatedly divide the absolute value (|-10| = 10) of the number by 2 until you get 0 in the quotient:

(10 / 2 = 5 R 0)
(5  / 2 = 2 R 1)
(2  / 2 = 1 R 0)
(1  / 2 = 0 R 1) // zero is the value in the quotient so we stop dividing

Place the remainders in order to obtain the binary equivalent:

1010

For an 8-bit cell the answer is 0000 1010, 16-bit cell 0000 0000 0000 1010, and so on.

Take the one's complement by inverting the bits (we will assume an 8-bit cell holds the final value):

0000 1010
1111 0101 // bits are inverted

Now take the 2's complement by adding 1:

 1111 0101
+        1
----------
 1111 0110 // final answer

What happens with a 4-bit cell?

The one's complement would be:

1010
0101 // inverted bits

Taking the 2's complement produces:

 0101
+   1
 ----
 0110 // final answer for a 4-bit cell   

Since the number should be negative and the result does not indicate that (the number begins with 0 when it should begin with a 1) an overflow condition would occur.

4
  • very detailed +1. You might want to mention Big/Little Endian too. Jan 29, 2010 at 5:52
  • @Johannes: Endianness doesn't come into picture when talking about binary representations. That's only significant when > 1 byte is stored in a computer. @Brandon: nit: it's ones' complement, not one's. Jan 29, 2010 at 6:30
  • @Alok: yep, see the 16 bit cell ^^ Jan 29, 2010 at 6:45
  • @Johannes: Again, that comes into the picture only when storing a number in memory. It's equivalent to saying that the number "one thousand, two hundred and thirty four" has the representations 1234 or 4321 based upon endianness. The number has only one representation, it's only when we're storing it in memory do we talk about endianness. Jan 29, 2010 at 6:57
4

Take the binary form of 10, invert all the bits, and add one.

10       0000 1010
invert   1111 0101
add 1    1111 0110
3
  • 3
    Assuming twos complement and no overflow.
    – 3Dave
    Jan 29, 2010 at 5:25
  • Your answer is correct for an 8-bit cell. What about a 4-bit or 16-bit cell? Jan 29, 2010 at 5:30
  • @Brandon: The answer is correct regardless of word size; it just so happens that 10 will overflow a signed 4-bit word. Jan 29, 2010 at 5:38
1

Follow this link. You can find the binary form of a negative number say -n by finding out the two's complement of n.

1
  • You're assuming two's complement. There is no "the" binary form of a negative number. Jan 29, 2010 at 6:46
1

Your question has no "right" answer. First, you have to define the representation you want to use. Do you want to use two's complement, ones' complement, sign-magnitude, or something else? Then you have to define how many bits to use.

Let's say we are working with 5-bits wide representations.

+10: 0 1 0 1 0

Let's look at sign-magnitude system. In this system, the most significant bit (bit 5) is 1 if a number is negative, and 0 otherwise. The rest of the bits represent the magnitude (absolute value) of the number.

So we get:

-10: 1 1 0 1 0 (sign-magnitude, 5 bits)

Let's look at ones' complement now. Here, a negative number is represented by just changing 1s to 0s and vice-versa (hence the name ones' complement—you complement a number with respect to a long sequence of 1s).

So we get:

-10: 1 0 1 0 1 (ones' complement, 5 bits)

Finally, let's look at two's complement system. In this, we take a number in its ones' complement system, and then add 1 to it.

So we get:

-10: 1 0 1 0 1
             1
     ---------
     1 0 1 1 0 (two's complement, 5 bits)
     ---------

Thus, the binary representation of a negative number depends upon the system we use, and the number of bits available to us.

Also, you might have noticed the position of the apostrophe in ones' complement and two's complement. Why is is not one's complement or twos' complement? Then answer, from Knuth:

A two's complement number is complemented with respect to a single power of 2, while a ones' complement number is complemented with respect to a long sequence of 1s. Indeed, there is also a "twos' complement notation," which has radix 3 and complementation with respect to (2...22)3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.