C usual arithmetic conversions
Indeed b
is converted to unsigned. However what you observed is that b
converted to unsigned and then added to 10 gives as value 5.
On x86 32bit this is what happens
-
b
, coverted to unsigned, becomes4294967291
(i.e.2**32 - 5
) - adding 10 becomes 5 because of wrap-around at
2**32
(2**32 - 5 + 10 = 2**32 + 5 = 5
)
0x0000000a
plus 0xfffffffb
will always be 0x00000005
regardless of whether you are dealing with signed or unsigned types, as long as only 32 bits are used.