August 13th, 2024

0xCAFEBABE & 0xFEEDFACE

The origins of magic numbers 0xCAFEBABE and 0xFEEDFACE in Mach-O and Java files were discussed, revealing their selection process and the amusing anecdotes behind them, highlighting computer history's complexities.

Read original articleLink Icon
CuriosityAmusementNostalgia
0xCAFEBABE & 0xFEEDFACE

The discussion revolves around the origins of the magic numbers 0xCAFEBABE and 0xFEEDFACE, which are used in Mach-O file formats and Java class files. The conversation began among former NeXT employees, with one participant questioning why Java adopted 0xCAFEBABE as its magic number. Mike DeMoney, who worked at NeXT and later at Sun, clarified that he did not choose the magic numbers for Java, as they were established before his arrival. He speculated that the similarity might stem from the limited number of appealing hex words available. James Gosling, a key figure in Java's development, later explained that he chose 0xCAFEBABE while looking for hex words to use as magic numbers for file formats, inspired by a local café's name. He initially used CAFEDEAD for another format, but it was eventually discarded. The conversation highlights the amusing and often convoluted nature of computer history, where stories can evolve and be misattributed over time.

- The magic numbers 0xCAFEBABE and 0xFEEDFACE are used in Mach-O files and Java class files.

- Mike DeMoney clarified he did not choose the magic numbers for Java; they were selected before he joined the team.

- James Gosling revealed that 0xCAFEBABE was chosen based on a café's name and the search for appealing hex words.

- The discussion illustrates how computer history can be shaped by anecdotes and misattributions.

- The limited number of interesting hex words may explain the coincidence of similar magic numbers across different platforms.

AI: What people are saying
The comments reflect a lively discussion about magic numbers in programming, particularly in relation to the article's focus on 0xCAFEBABE and 0xFEEDFACE.
  • Users suggest alternative magic numbers, such as 0xDECAFBAD and 0x4D494B45, sharing personal anecdotes about their use.
  • Several comments mention the concept of hexspeak and its amusing implications in coding.
  • There is a discussion about programming languages like Rust that flag the use of specific magic numbers.
  • Some users share their experiences with creating or using random hex values for fun or practical purposes.
  • Overall, the comments highlight the creativity and humor found in the use of magic numbers in programming.
Link Icon 17 comments
By @cdchn - 8 months
I'm surprised they didn't use 0xDECAFBAD for the Java format.

Even more interesting is the Wikipedia page https://en.wikipedia.org/wiki/Hexspeak catalogs a delightfully long list of hexspeak words and what they're used for.

By @mikehollinger - 8 months
Semi-related story with some insider baseball:

There are quite a few memorable words you can spell using 32 or 64 bits—like BA5EBA11. This is the story of me -not- choosing one of those.

These bit-pattern words are handy because they’re easy to recognize, especially in a random memory dump.

On my first “real” assignment, I was writing real-time embedded C code for a 16-bit processor that communicated with a host microprocessor on a server. We needed to run periodic assurance tests across a bus to ensure reliable communication with the host since we weren't constantly using the bus.*

We were given an unused register address on the host processor and told to write whatever we wanted to it. The idea was to periodically write a value, read it back, and if we encountered any write errors, incorrect reads, or failures, we’d declare a comm error and degrade the system in a controlled manner.

Instead of using zeros or something like 0xDEADBEEF, I decided to write 0x4D494B45 - "MIKE" in ASCII. It was unique, unlikely to be tampered with, it worked, and no one argued with me. The code shipped, the product shipped, and all was well. We even detected legitimate hardware errors, which I thought was pretty cool.

Fast forward two generations of systems, and long after I’d moved on from that team, the code had been ported around but that assurance test remained unchanged. Everything was fine until they brought up a new generation of systems, flipped on the firmware for that device, and 10 seconds later, my assurance test clobbered an important register. The entire system promptly checkstopped and crashed. It took the team days to figure out what was wrong, and I had to explain myself when they found "MIKE" staring back at them from the memory dump.

That was a fun project. ;-)

* Note: It would've been bad if our device went out to lunch because we were responsible for energy management of the server. If the power budget was exceeded and we couldn't downclock and downvolt the processor, something might have crashed or been damaged.

By @Dwedit - 8 months
A side benefit of the 2GB address space limit for 32-bit Windows programs is that magic numbers are not valid pointers, and will instantly cause an access violation if used.
By @lifthrasiir - 8 months
My preferred way to make a "magic" constant has been using base64. For example, 0x31a82270 maps to base64 `MagicA==`. This approach is most useful when the magic constant itself shouldn't be obviously ASCII but still should be meaningful enough.
By @novagameco - 8 months
Rust will yell at you if you use specific magic numbers like these

edit: yes, 0xCAFEBABE is a warning but 0xFEEDFACE is not:

3405691582

https://github.com/rust-lang/rust/blob/d0ea1d767925d53b2230e...

By @mikewarot - 8 months
0x08675309 also shows up fairly often.
By @0xbadcafebee - 8 months
Welp, time to trademark the old handle.
By @dec0dedab0de - 8 months
a long time a go I wrote a script that spit out random phrases in hex that would work as a mac address. I used to do this to mess with my coworkers in networking , and previous coworkers at the ISP I was still using. My HN username is the only one i remember though.
By @malkia - 8 months
0xC05FEFE
By @amsterdorn - 8 months
What about 0xDEADBEEF?
By @leejoramo - 8 months
Great to see these UserLand Radio Blogs are still hosted all these years later. Dave Winer (and I am sure others) obviously worked to see that happen.
By @Jupe - 8 months
= CAECBA8E
By @rr808 - 8 months
0xDDDB00B5