Cap'n Arbyte's


Local interest

Other sites


Malarkey Numbers

In a bid to further alienate the economics / politics / finance audience I've built up over the years, let's talk about the super-fun subject of math.

Why? Because I hit a mathematical coincidence at work that was both amusing and time-consuming. Here's some simplified background to explain the situation. I'll phrase it in terms of software pointers, but my circumstances actually involved hardware.

I was looking at a number that I knew was an index into an array of 4-byte values. These values happen to be byte-addressable, however, so it's sensible to also think about them as a byte array. Recall your introductory programming classes where you learned that for int * p, the value of p+1 is "really" p+4 because each int is four bytes wide.

I became confused because I was comparing the indices of nearby array elements in two different contexts — in one, adjacency showed up as ±1 and in the other, adjacency showed up as ±4. My natural suspicion was that the ±1 numbers were the "array index" numbers and the ±4 numbers were the "pointer offset" numbers. Except that didn't make sense, because to scale an array index to a pointer offset you have to multiply by 4, yet the two numbers I was looking at were both the same: 8478. No scaling by 4! How could this be? I suspected there was a bug in the code that generated my information.

I'll cut to the punch line. There was no bug, but something else was going on here. The first set of numbers was displayed in decimal and the second set of numbers was displayed in hexadecimal (without a leading 0x to disambiguate). And it just so happens that when you take decimal 8478, multiply it by four, and convert the result to hexadecimal … you get 8478. Everything was fine, just a little ambiguous in the presentation. Problems like this are exactly what the 0x prefix is for.

I did a little math (which I'll now share with you) and realized that there are many such numbers. A friend suggested I seize the opportunity to christen these "malarkey numbers" in honor of a famous misstatement of my last name at an award ceremony several years ago. So, here goes:

Malarkey Number
A number whose hexadecimal textual representation is identical to the decimal textual representation of the number multiplied by four.

A little analysis leads us to some interesting properties flowing from this definition. Here's an analysis for 4-digit numbers, like I accidentally hit:

4 * (1000*a + 100*b + 10*c + 1*d) = 4096*a + 256*b + 16*c + 1*d
              144*b + 24*c + 3*d  =   96*a
               48*b +  8*c +   d  =   32*a
32a = 48b + 8c + d, where each of a b c and d ∈ {0 .. 9}

A few properties are quickly apparent: There are no malarkey numbers of fewer than than 4 digits (a=0). The first digit (a) is necessarily greater than the second digit (b). The last digit (d) can only be 0 or 8, because all the other terms are multiples of 8.

Let d=0 and the expression simplifies to 4a=6b+c, implying c is even. Let d=8 and the expression simplifies to 4a=6b+c+1, implying c is odd.

A quick brute-force search (aren't computers wonderful?) confirms these properties and provides the full list of four-digit malarkey numbers, making some latent patterns visible:

0000 1038 1040 2078 2080 2118 2120 3158 3160 3200
4198 4238 4240 5278 5280 5318 5320 6358 6360 6400
7398 7438 7440 8478 8480 8518 8520 9558 9560 9600

Isn't it interesting how they "mostly" come in pairs, 2 apart?

Also interestingly, all malarkey numbers (except zero) are four digits. All extra digits wind up on the same "side" of the equation as "a", but have coefficients so large that the equality can never hold unless these new digits are all zero.

Therefore, the above is the complete list of malarkey numbers. There are only thirty, and I stumbled upon one of them totally by accident. In a huge list of mostly ordinary numbers, the first one I looked at happened to be a malarkey number. Just my luck.

Tiny Island