40 year old bug fixed

I have it on good authority that Apple have fixed one of the longest running bugs in Mac OS, and other computer OSes in Snow Leopard. This is the mother of all long running bugs. It’s been about for 40 odd years.

Which bug am I talking about? For all this time, all these OSes have been reporting a 1,024 bytes to be 1kB, 1,048,576 bytes to be 1MB, 1,073,741,824 bytes to be 1GB etc. an obvious inaccuracy, the SI prefix (pre-existing since the 50s) definitions very specifically say that 1,000 anythings is 1 kilo anything; 1,000,000 anythings is 1 mega anything; and 1,000,000,000 anythings is 1 giga anything.

But where did such an obvious bug come from, and why did it persist for so long? Way back when, when binary computers were first being created, shifting a binary number right by 10 places was a very fast operation. That meant that division by 1024 was extremely cheap. In the mean time, division was one of the most expensive operations on a CPU, if it was available at all. Often, one would need to simulate it with a bunch of other mathematical operations to home in on the correct value. The result was that in those days, we were prepared to accept being off by 24 measly bytes, in exchange for a large chunk of efficiency.

Of course, over time, it became common knowledge that 1024 bytes was 1 kilo byte. The fact that this was incorrect was by the by. And so it became common knowledge that obviously a mega byte would be 1,048,576 bytes, etc etc. The issue these days of course is that you go out and you buy a 1TB disk, the hard drive maker has accurately reported the disk’s size as being 1,000,000,000,000 bytes, your OS meanwhile would report it’s size as only 909GB because it divided by 1,099,511,627,776 instead of 1,000,000,000,000.

So what’s changed? Well, yay! Snow Leopard now correctly divides by 1000, instead of 1024!

As an afterthought by the way, there are names for the more convenient to divide by prefixes. They’re kibi, mebi, gibi, tebi, pebi, exbi, zebi and yobi, which are shortened to Ki, Mi, Gi, Ti, Pi, Ei, Zi and Yi.