I could not understand the example in LRM.
“11.3.3 Using integer literals in expressions” says:
Note that -12 and -'d12 both evaluate to the same two’s-complement bit pattern, but, in an expression, the -'d12 loses its identity as a signed negative number.
int IntA;
IntA = -12 / 3; // The result is -4
IntA = -'d 12 / 3; // The result is 1431655761
( 1431655761 == 0x55555551, so value before dividing by 3 is 0xFFFFFFF3 )
I could not understand why the result is as such. Does anyone help me understand how it works?
I thought as below. Is this correct?
- As IntA is 32bit, 'd12 is internally treated as '32h0000_000C
- – ('d12) is the same as ~('d12), so -'d12 is treated as 32’hFFFFFFF3, thus result is 1431655761.
Thanks