5. How are negative numbers stored #
Created Thursday 17 October 2019
- Range of storing the numbers is (-2^31, 2^31 - 1) for int in a typical compiler.
- They are stored using the 2’s complement for integers.
- The number with the biggest magnitude, which in int is 2^31, is represented differently, i.e 1 followed by 31 zeros. This is the non unique zero for the case.
Some experiments(always remember these):
- if char is initialized/assigned an int value, only the last byte gets copied. With a warning, if int > 255.
- if unsigned int is initialized/assigned to an unsigned value, the whole negative number is stored in the 2’s complement. Then the 2’s complement tag is removed. i.e the whole number is considered as the unsigned value, without the sign bit.
- **IEEE 754, **1985 - using the sign bit as the primary basis for float representation.