1. (Mumble-mumble) years ago I happened to work, briefly, with an electronic calculator in an office. What fascinated me was that if you subtracted 1 from zero, you’d get all 9’s. This was the accidental mechanical analogue to the way negative numbers are stored in binary numbers, e.g., in a two-byte binary number, 0-32767 are positive, and Hex FFFF thru Hex 8000 are considered -1 to -32768. Because the sign bit (the leading bit, here) is a side effect of the storage mechanism and not really an independent sign bit, overflows from + to – and – to + are common and the source of many bugs. Nowadays, with the common use of 4 and 8-byte binary numbers, overflows are less common, but if you have a runaway loop based on a binary counter that large, you’ll wind up chewing up CPU, sometimes for minutes, before you get that overflow exception.

Comments are closed.