Question

I need to find out that how can we represent -1 and -3 in minimum number of bits in Two's complement number system. I calculated the answer 1 and 111 but the answers seem to be incorrect. I would be very thankful if I can get some help. Thanks

Was it helpful?

Solution

Here's the formula you're probably already familiar with: N' = 2^n - N. Where n is number of bits, N' is the decimal representation of -N's complement, and N is the cardinal number. For example, short int x = -6 is going to be N' = 2^8 - 6 = 250 when converted to unsigned short int.

Now, with this formula, you can get n = log(N+N') (log of base 2).

Edit:

I was more focused on just the number of bits. Now I've re-read your question... Let me give you an answer: You need at least two bits to represent 3 and you need that one extra bit to represent signness, which means you need at least 3 bits to represent -3. Same goes for 1. Having that in mind, [011] = 3, take the complement of one (inverting bits) => [100] and add 1 => [101] = -3. As for the -1, you do the same. [01] = 1, invert the bits => [10] => add one => [11] = -1.

That's it, I think...

OTHER TIPS

-1 can be represented by 1 and -3 can be represented by 101 (-4 + 1).

111 is equal to decimal -1 (-4 + 2 + 1).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top