how operators can be used for both signed and unsigned no:s?
How is the memory representation of signed and unsigned no:s in C?
Singed integers are typically represented with two's complement representation. To represent a negative number, take the complement of the positive equivalent and add 1:
Consider these 8-bit numbers:
-18 = ~(00010010) + 1
= 11101101 + 1
= 11101110
Now if you want to subtract 18 from 23, you can simply use addition and two's complement:
23 = 00010111
-18 = 11101110
---------------------
5 = 00000101
Overflow is ignored.
Now, for floating point numbers, that's a whole different story.
columbine
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment