views:

46

answers:

1

Say I had a 6 digit hexadecimal signed in two's complement. What would be its range?

-(16 ^ 5) < x < (16 ^ 5)

Correct?

+1  A: 

This sounds like homework. If so, please tag your question as such.

One way to think about this:

  • How many bytes are represented with 6 hex digits?
  • How many bits are represented with those bytes?
  • How many bits do you lose due to the sign?
  • Given your total number of bits, what is smallest value you can represent?
  • Given your total number of bits, what is the largest value you can represent?

Think hard about the answer to the last question.

For example, the smallest signed 32-bit int is -2147483648. The largest signed 32-bit int is 2147483647.

Chris Schmich
Not homework, just for an application i'm developing.That means the maximum positive value is 8388607 but 0FFFFF = 1048575
Ben
The max positive value is 0x7FFFFF == 8388607 == 2^23 - 1 == 0b011111111111111111111111. You don't lose a whole hex digit for the sign bit, you just lose the leading bit. The other 23 bits are still usable as part of the value.
Chris Schmich