jump to navigation

Another expensive bug June 21, 2017

Posted by Peter Hornby in software.
add a comment

Around eight years ago, I wrote about the strange case of the gentleman from New Hampshire whose bank debited his account by 23 quadrillion dollars after he bought a pack of cigarettes at a gas station.   This still looks like a fairly straightforward bug, made amusing by the size of the miscalculation.

It looks like data representation has raised its ugly head once more, in the shape of the case of the lady who seemingly won 43 million dollars in a casino.  The casino has offered her a steak dinner and her money back and, maybe not surprisingly, she’s suing them.

Here’s the machine’s display showing her win:170615181842-katrina-bookman-slot-machine-lawsuit-780x439

Let’s look at that number – $42,949,672.76.   If you convert this decimal value (the number of cents) to unsigned binary, you get (represented as hexadecimal) 0xFFFFFFEC.  What else does that bit string represent?  It turns out that if you regard it a signed value, the decimal equivalent is -20.

It looks as though the game software performed an arithmetic calculation that it confidently expected to produce a positive result – I assume that the calculation was supposed to produce the value of her win – and displayed the value accordingly. Unfortunately, the result of the calculation was a negative value – it looks like the program had concluded that she’d won -$0.20.  Displaying this value assuming that it was unsigned gave the result seen by Katrina Bookman.

Prove it.  Write a small program that declares an integer variable initialized to the value -20.  Display the resulting value using the format string appropriate for an unsigned value.  See the value 4294967276.  Here are two lines which do it.

int ui = -20;
printf_s("Value = %u\n", ui);

Value = 4294967276

 

 

Advertisements

A quadrillion dollars in debt July 15, 2009

Posted by Peter Hornby in software, tech.
4 comments

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.

Jim Gray – LA Times version May 30, 2008

Posted by Peter Hornby in software.
add a comment

Look, I know it’s hard to describe someone as multi-contributory as Jim Gray in one paragraph, but, really, I think Michelle Quinn, in her story in this morning’s Los Angeles Times, might have done better than this:

The daylong event honoring the computer-science whiz who helped create automated teller machines will be part celebration, part science fair.

“The computer-science whiz who helped create automated teller machines”?  That’s it?  Really?

I guess it’s possible that Michelle Quinn’s research led her to the Microsoft press release announcing Gray’s 1999 Turing Award, which has this as its subheading

Gray’s database research paved the way for ATM machines, computerized airline reservations and e-commerce. The Microsoft senior researcher this month received the prestigious A.M. Turing Award-the “Nobel Prize of computer science”-for his contributions.

The Times story is actually pretty good once you make it past the open.  It talks at some length about tomorrow’s tribute symposium at Berkeley, and spends more time on Gray’s wife Donna Carnes, and her life since his disappearance, than it does on his life and achievements.

Build your own font May 13, 2008

Posted by Peter Hornby in software.
add a comment

I’ve never developed a font.  I don’t suppose many people have.  It’s always seemed as though you need expensive tools, planetary-level creative skills and, let’s say, a tendency to the obsessive.  Well, some of those barriers to entry have just been broken down with the release of FontStruct, a free web-based font construction tool from a font house called FontShop.

The metaphor is simple.  You fill a rectilinear grid with bricks.  OK, it’s just pixel editing. But the bricks can be odd shapes, so you can round off corners and end up with some radical character shapes.  Once you’re done, you can save your work, and download a TrueType version for use in your own work, or you can share your font with other users.

I have to say that FontStruct is really well done.  You have the tools you need, and no more.  The interface is clean and attractive.  All in all, an excellent job.

So, building a font is now simple.  Of course, designing a great font is exactly as hard as it was before, and for that, you’re on your own.

Thanks to Jason Kottke for the tip.