A quadrillion dollars in debt July 15, 2009
Posted by Peter Hornby in software, tech.trackback
After an unconscionable period of quiet, the blog bursts into life with a post which will probably only be of interest to a small subset of my vast reader audience.
The BBC reported today that some poor guy in New Hampshire discovered that his bank had debited his account by $23 quadrillion dollars after he bought a packet of cigarettes at a local gas station.
The story concludes:
But no-one has yet explained to Mr Muszynski how such a astonishing error could have been made.
I’m here to help.
The amount quoted in the story is $23,148,855,308,184,500.00
Type eight space characters into a text editor. It’ll look like “ ” on screen (minus the quotes, of course). What has the computer stored in memory? If your text editor uses the ASCII character-encoding scheme, you’ll get 3264 bits which look like this when represented hexadecimally – “2020202020202020″. Each “20″ is the ASCII representation of a space character.
Here’s where it gets interesting. Suppose you tell the computer that this memory location doesn’t contain a string, but a decimal value, what do you get? The answer is 2314885530818453536. I’m not sure how the bug manifested itself, but it seems likely that some memory location which was supposed to contain the number of cents in the debit amount was actually overwritten with a text string which was all, or almost all, spaces.
Oh well, geek credentials established. Now back to hummingbirds and choral music.
Updated: Peter points out in comments that eight spaces take 64 bits, not 32. Indeed they do (slaps forehead in annoyance). He also points out that “2020202020201250″ converts exactly to the correct decimal value, and wonders whether the pack of cigarettes cost $12.50. Maybe. Thanks for the notes, Peter.
Minor point, those eight spaces would be stored in 64 bits, not 32, Which I’m sure is what you meant :)
Also a hex value of “2020202020201250″ gives the precise result in decimal. I wonder whether $12.50 was the cost of the goods.
I’m quite ok with you deleting my comment, but at least you might fix the errors in the text.
1 space = 8 bits.
8 spaces = 64 bits
Peter – sorry for the delay in approving your comment. I had to leave for a while. No slight intended, and your comment is valuable and appreciated.