1

Let's just look at a signed char. A char has 8 bits. The max value is 127 which makes sense to me but why is the min value -128. Let's say if the first number is 1 it's + and 0 is -

1 1 1 1 1 1 1 1

'+' 64 32 16 8 4 2 1 = +127 <- makes sense

0 1 1 1 1 1 1 1

'-' 64 32 16 8 4 2 1 = -127 <- so this should be -127 but why is it -128?

And thats for every signed value: char -128,+127 short -32768,+32767 and so on.

I really hope you understand my question if you have questions just ask.

hokk
  • 11
  • 2
  • Man I don't know how to use this website it formats so weirdly. Trying to fix it – hokk Feb 22 '22 at 18:47
  • It looks like you're assuming [signed magnitude representation](https://en.wikipedia.org/wiki/Signed_number_representations) (which is a reasonable thing to guess before you know the real answer) but [two's complement](https://stackoverflow.com/q/1049722/555045) is far more popular (and has a simpler implementation). You can mark this question as a duplicate of that one, if the answers there satisfy you. – harold Feb 22 '22 at 18:51

0 Answers0