1

I know the difference between one's and two's compliment integers, however I'm uncertain on whether a signed 16-bit integer is the same as either or both of those.

Hopefully an easy yes/no question.

phuclv
  • 37,963
  • 15
  • 156
  • 475

2 Answers2

2

Signed integer only means that the type can store negative values. It doesn't say anything about signed type representation which can be 1's complement, 2's complement or sign-magnitude... Even C and C++ standard nowadays don't force the use of 2's complement. But a signed type obviously can't be both 1's and 2's complement at the same time

In modern systems 2's complement is used exclusively (probably except some network devices) but older systems that use other signed representations exist, for example the UNISYS 2200 series

phuclv
  • 37,963
  • 15
  • 156
  • 475
1

Yes, saying an integer is signed is the same as saying it's using two's complement representation on your standard computer.

Darius
  • 190
  • 1
  • 10
  • 1
    wrong! there are other signed representations available – phuclv Mar 22 '16 at 05:14
  • Yes, there are other ways to do it, but the vast majority of the time a computer will use two's complement representation. That's why I said "on your standard computer", although you're right in that I could have worded it a bit better. – Darius Mar 22 '16 at 05:20
  • 1
    "vast majority" doesn't mean that "signed == 2's complement" – phuclv Mar 22 '16 at 05:22
  • You're right. I assumed the OP was asking what a modern computer uses instead of taking the question more literally. Thank you for the correction. – Darius Mar 22 '16 at 05:25