The standard baud rate 38400, if you write it in hex, becomes 0x9600, which is confusing, because 9600 (decimal) is another of the standard baud rates.

(I first encountered this fact while reading a hex dump of an SSH session. The SSH terminal setup packet has a baud rate field, and I saw 00 00 96 00 in the hex dump, and thought "fine, yes, baud rate, move on … wait, *what*?")

A much more well known hex/decimal coincidence is that 100 decimal = 0x64 hex, which looks confusingly backwards because you expect numbers that look round in *hex* to look like familiar power-of-2 things in *decimal*.

But these aren't separate coincidences: they're two facets of the same one.

Because if 100 = 0x64 and 256 = 0x100, then multiplying both together gives you a number that ends in two zeroes in both bases: 25600 = 0x6400. And you can divide by 2 to get 12800 = 0x3200, and multiply by 3 to get 38400 = 0x9600, without any carries on the hex side spoiling the fun.

I'm posting about numerical coincidences in the middle of the night, incidentally, because I woke up and couldn't get back to sleep.

Rolled over and looked at the clock. It read 4:04. Sinking feeling. "Oh hell, what's gone wrong *now*?"

@simontatham My favorite coincidence of this type is that 25 in decimal is 31 in octal. In other words dec 25 = oct 31, setting the stage for jokes about nerds confusing Halloween and Christmas.
@saltbaygull @simontatham Hallowe’en technically is on 1ˢᵗ November

@simontatham The important east-west highway that runs through Philadelphia is Interstate 76. People assume that this is to commemorate Philadelphia's important role as the place where the 1776 Declaration of Independence was signed. But no, Interstate highways are numbered from south to north and I-76 is so-called because it is somewhat north of I-70 and a bit south of I-78, leaving room for I-72 should they ever want to build such a thing.

Also, the emergency services number in the entire US is 911, and young people assume this has something to do with the September 11 disaster, but the choice predates that by decades.

@simontatham My wife once remarked that the choice of 404 was clever, since it suggests "File not found", with 0 representing "not". I had to sadly explain to her that this was pure coincidence.
@mjd the 911 thing reminds me of hearing that these days people learning about the Watergate scandal for the first time get confused that it didn't involve water, because all the other "-gate" scandal names are related to the word that came first.
@mjd @simontatham The north-south highway on the west side of the Willamette River in Portland, OR is Macadam Ave. / Hwy 43. By the principle of Scottish Highway Symmetry, the north-south highway on the east side is McLoughlin Blvd. / Hwy 99E. (John McAdam developed a road surface while John McLoughlin was the first white person in charge of things around these parts. Neither of them knew about Scottish Highway Symmetry during their lifetimes.) Hwy 99W does exist, but it's a few miles to the west. It meets Hwy 99E farther south in Junction City, OR. Junction City's name has nothing to do with this fact; it was named for a railroad junction.
@mjd @simontatham I remember the 911 thing being described to me as a child (in the US) in the early 00s as "the terrorists picked September 11 because it looks like the emergency number." In retrospect, I should have understood that as a manifestation of the general insanity of the era.

@ohdeargodwhy @mjd that was definitely a theory I remember hearing when it happened, though I'm pretty sure nobody ever proved whether or not it was really part of the terrorists' motivation!

Tangentially, I also remember a poster-style image circulating on the British parts of the Internet depicting our Houses of Parliament blowing up, as if the Gunpowder Plot of 1605 had succeeded, and in the corner of the image, the caption '5/11'. Struck me as an almost stereotypically British thing to do – refer to an American disaster in such a way that you get in a dig at them writing dates the wrong way round!

@simontatham @ohdeargodwhy The terrorists actually chose that day to draw attention to the unjust and centuries-old occupation of Catalonia by the Castillian imperialist aggressors. Sadly, that part of their message was ignored. https://en.wikipedia.org/wiki/National_Day_of_Catalonia

#itsTrue

National Day of Catalonia - Wikipedia

@simontatham

Oh hell, yes.
Will forever remember this, when I wake up in the middle of the night, feeling like the only person on the world who wakes ip because of strange numbers

@simontatham Imagine looking at the clock one minute earlier, being denied a time reading.
@jyrgenn worse would be if it said 3:02 and I had to get up and go and look at a different clock.
@simontatham That makes me think some network vendors got the 9600 bps wrong and thus ended up with 38400 instead. Somehow would not be surprised.
@databeestje on the other hand, probably that was so long ago that octal was still the fashion!
@simontatham I should not have read this so early in the day. I think you just broke my programmer brain.
@[email protected] The famous one is

OCT 31 = DEC 25

@simontatham

I always found 64206 fascinating as it's right in your 0xface

@simontatham here is another fun one: I'm looking at code that converts a string of decimal digits to a 32 bit number. It uses the value 0x19999999, because that's the largest value you can multiply by 10 (resulting in 0xfffffffa), and add another number (<=5) to it without overflowing.
@pulkomandy ah, I think that's related to https://hachyderm.io/@simontatham/111498791186244376 in which I got confused by the fact that 0.199999 is very close to 0x1.999999 × 2⁻³. The latter is true _because_ of your point that 0x19999999 is very close to 1/10 of 0xFFFFFFFF (or of 0x100000000). And of course 0.199999 is very close to 1/5 of 1, leaving only factors of 2 to vary between the two.
Simon Tatham (@[email protected])

Very confused just now to print the number 0.1999999 using the printf %a format (hex floating point) and get something like 0x1.999999p-3. My first thought was that somehow it was accidentally still printing in decimal! But no, those two numbers really are equal (in the limit as you add more nines), by a silly coincidence. That's almost as confusing as the time I accidentally printed a baud rate in hex and didn't notice, because 38400 == 0x9600, so it still looked plausible.

Hachyderm.io

@simontatham looking at the bit representation, each 9 hexdigit when you multiply by 10 results in 90=0x5A, and when you shift that by a digit (4bits), you get all the bits set for a digit and no carry. So:

0x9 x 10 = 0x5a
0x99 x 10 = 0x5fa
0x999 x 10 = 0x5ffa
...

adding the leading 1 adds 10 (0xA) to the leading 5 in the result, getting you another F. So it works with any number of hexdigits

@pulkomandy or, perhaps more simply: 1/5 of F is 3, so 1/5 of any string of FFFFF is an equally long string of 33333. And shifting that right by 1 bit to turn 1/5 into 1/10 moves the low bit of each 3 into the top bit of the digit below, turning 3333...3333 into 1999...9999 with a bit shifted off the bottom.

@simontatham: I read a blog post (https://aggviolinist.medium.com/reversing-kr-music-player-d87c7ebc589c) last night and found that 60 seconds is the same as 0xEA60 milliseconds. Yes.

Because Electronic Arts.

Reversing.kr Music player - manadrila - Medium

Hello hackers today I’ll be reversing another executable. What would you do if your music player only played your favorite music for only one minute? Sounds so weird. In today’s challenge we’ll be…

Medium
@simontatham: if you're reading it in a hex editor, it'll likely show as 60 EA 00 00 (little endian).