3 ms·
Actually a 63 bit number and a 1 bit sign flag Not true. Modern architectures use 2s-complement rather than an explicit sign bit to represent integers. If you
by MichaelSalib 14y ago
Actually a 63 bit number and a 1 bit sign flag
Not true. Modern architectures use 2s-complement rather than an explicit sign bit to represent integers. If you use a sign bit, there are two different zeros (positive and negative) but the range of positive numbers is exactly as large as the range of negative numbers. With 2s-complement, there's only one zero and the range of negative numbers is larger (by one) than the range for positive numbers.
- dschatz 14y agoIn 2s complement, the most significant bit is the sign bit. In fact all valid C integer representations have a sign bit.
- cube13 14y agoSigned integer representations. Unsigned ints do not, and you're given the full range of the integer as valid data.
- dschatz 14y agoYes you're right. I should have been more specific that all signed integers have a sign bit.
- to3m 14y agoI think his point is that changing a sign bit doesn't affect the absolute value, just its sign. A sign bit has no value itself - it's just a flag. If the representation has a sign bit, you'd have a negative zero. But the top bit in 2s complement has a value - it's just a negative one (that's large enough to make any value with it set negative). That's not a sign bit! If you change it, the absolute value most definitely changes, and quite substantially.
- MichaelSalib 14y agoThis is wrong. Take an integer value x. Flip the sign bit. Do you now have the value -x? On a 2s complement architecture, you do not. In 2s complement, you have to flip all the bits and add one to get -x.
- dschatz 14y agoSign bit means one bit represents the sign of the integer which is the case with the most significant bit in 2s complement. If you flip the sign bit, the sign changes. It does not mean that if you flip the sign, the value is negated.
- xentronium 14y agoThis is a technicality. Leftmost bit still denotes a sign and modulo of the number is still capped at n-1 bits.
- MichaelSalib 14y agoThe differences between the representations matter. In 2s complement, -INT_MIN is not INT_MAX; in fact, -INT_MIN is undefined and a C compiler is justified in deleting all your code if you ever cause it to calculate -INT_MIN. I tell you what: if you think modern architectures use an explicit sign bit to represent integers, how do you explain the fact that INT_MAX+1==-INT_MIN? If there's a sign bit, how could you possibly represent more negative integers than positive integers?
- Arelius 14y agoAre you arguing that given such, I have more than 63 bits for the number, or do you just have a problem with the usage of the words "sign flag"?