views:

437

answers:

4

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

+3  A: 

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

10       0000 1010
invert   1111 0101
add 1    1111 0110
Ignacio Vazquez-Abrams
Refer to two's complement: http://en.wikipedia.org/wiki/Twos_complement
Lytol
Assuming twos complement and no overflow.
David Lively
Your answer is correct for an 8-bit cell. What about a 4-bit or 16-bit cell?
Brandon
thanks for answer. yes what about 4 bit cell ?
Dinesh
@Brandon: The answer is correct regardless of word size; it just so happens that 10 will overflow a signed 4-bit word.
Ignacio Vazquez-Abrams
+3  A: 

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

Prasoon Saurav
You're assuming two's complement. There is no "the" binary form of a negative number.
Alok
+4  A: 

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.

Brandon
very detailed +1. You might want to mention Big/Little Endian too.
Johannes Rudolph
@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**.
Alok
@Alok: yep, see the 16 bit cell ^^
Johannes Rudolph
@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.
Alok
+1  A: 
Alok