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
I need to find out that how can we represent -1 and -3 in
Share
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
Nis the cardinal number.For example,
short int x = -6is going to beN' = 2^8 - 6 = 250when converted tounsigned 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…