Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Minimum Number of Bits Required for Two's Complement Form

On my midterm, there was a question stating:

Given the decimal values, what is the minimum number of bits required to represent each number in Two's Complement form?

The values were: -26, -1, 10, -15, -4.

I did not get this question right whatsoever, and the solutions are quite baffling.

The only part I really understand is finding the range in which the value is located. For example, -15 would be within the range of [-2^5, 2^5), and -4 would be in the range from [-2^2, 2^2). What steps are needed from here in order to find how many bits were necessary?

I tried finding some pattern to solve it, but it only worked for the first two cases. Here's my attempt:

  1. First I found the range. -2^6 < -26 < 2^6

  2. Then I found the value for 2^6 = 32.

  3. Then I found the difference between the "closest" bound, and the value.

-26 - (-32) = 6

Again, this worked for the first two values by chance, and now I'm stumped as to find the actual relation between the number of bits required for an integer to be represented in Two's complement form, and the actual integer.

Thanks in advance!

like image 742
Andrew T Avatar asked Dec 07 '13 00:12

Andrew T


People also ask

How many bits are needed for 2s complement?

Remember that the scheme two's complement can represent both positive and negative integers. Since this problem calls for eight bits, put another bit on the left. The eight-bit two's complement representation of positive 85 is 01010101 .

What is the minimum number of bits required to store the answer in two's complement?

Show activity on this post. Minimum number of bits required to represent (+32)base10 and (−32)base10 in signed two's compliment form? So to represent +32 we need 7 bits. So to represent −32 we need 7 bits.

What is the minimum value in 8 bit two's complement?

The Correct Answer is -128. The smallest integer that can be represented by an 8- bit number in 2's complement form is -128.


1 Answers

First off, you're off on your powers of 2. 32 = 25.

Anyway, I followed you through the first two steps. Your last step doesn't make sense.

  1. Find the power-of-two range that brackets the number. You want a power-of-two range of the form [-2N, 2N - 1]. So, for -26, that would be -25 &leq; -26 &leq; 25 - 1. That corresponds to -32 &leq; -26 &leq; 31.
  2. Number of bits for the 2s complement representation will then simply be N plus 1. The "plus 1" accounts for the sign bit. For -26, that's 5 + 1 = 6.

So, for each of the numbers you gave: -26, -1, 10, -15, -4.

  • -25 &leq; -26 &leq; 25 - 1 becomes -32 &leq; -26 &leq; 31, which gives 5 + 1 = 6.
  • -20 &leq; -1 &leq; 20 - 1 becomes -1 &leq; -1 &leq; 0, which gives 0 + 1 = 1.
  • -24 &leq; 10 &leq; 24 - 1 becomes -16 &leq; 10 &leq; 15, which gives 4 + 1 = 5.
  • -24 &leq; -15 &leq; 24 - 1 becomes -16 &leq; -15 &leq; 15, which gives 4 + 1 = 5.
  • -22 &leq; -4 &leq; 22 - 1 becomes -4 &leq; -4 &leq; 3, which gives 2 + 1 = 3.

Got it?

The -1 one is tricky...

like image 158
Joe Z Avatar answered Sep 23 '22 14:09

Joe Z