I just started reading Hacker\'s Delight and it defines abs(-231) as -231. Why is that?
I tried printf(\"%x\", abs(0x80000000))
on a f
I think the way abs
works is to first check the sign bit
of the number. If its clear do nothing as the number is already +ve
else return the 2's complement
of the number. In your case the number is -ve
and we need to find its 2's complement
. But 2's complement of 0x80000000
happens to be 0x80000000
itself.