Hacker News new | past | comments | ask | show | jobs | submit login

When I first learned two's complement I sort of accepted it as something to memorise for a test and didn't really understand (or care) why it worked.

What really made it click for me was thinking of it as modular arithmetic. If you consider 8-bit integers, they range from 0-255 and you're actually working modulo 256. So you can think of 0-127 as your non-negative numbers. The numbers from 128-255 behave as negatives modulo 256 (e.g. -1 mod 256 = 255).




Good point; I wish I'd added that.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: