26

I found this question asking about the origin of 0x to denote hexadecimal to be interesting.

However, when I cut my teeth programming on 8-bit 65xx systems in the early 80's everything I saw used a $ to denote hexadecimal digits (assemblers, monitors, books, magazines, etc). It wasn't until I got my first Amiga 1000 and started to learn C that I even knew the 0x prefix was a thing.

If the 0x prefix clearly predates the 8-bit revolution, then (1) why was $ adopted so widely? And the opposite, (2) having become ubiquitous for a whole generation of 8 bit programmers, why was it abruptly dropped? (Not that it matters, but I still use $ when commenting code or scribbling on dead trees.)

  • 6
    I know that Intel used 12H for hex, while Motorola used $12, so that explains why it was adopted widely for 8-bitters. But I am not sure if Motorola invented it, or copied it from somewhere else. – dirkt Aug 16 at 10:44
  • 3
    It's also C vs Pascal - C uses 0x whereas Pascal (Turbo) uses $. – No'am Newman Aug 16 at 12:43
  • 1
    @No'amNewman: Consider writing an answer. – DrSheldon Aug 16 at 13:58
  • 2
    I'm an old IBM 1130 programmer: hexadecimal literals should start with "/". – John Doty Aug 16 at 21:10
  • 1
    I remember that widely used HiSoft's DevPac (GENS) assembler for the ZX Spectrum (and some other Z80-based computers) uses the # mark for hexadecimal numbers: #CAFE – Martin Maly Aug 17 at 5:39
21

Short Answer:

Motorola used it for their 6800 and MOS (6500) inherited it from Motorola. After all, the 6500 team members came out of the 6800 project so they were already used to it.


Long Answer:

If the 0x prefix clearly predates the 8-bit revolution,

It doesn't, really. Motorola used the $ prefix already with the 6800 of 1974. Unix had only recently (1973) been rewritten in C, which added the 0x convention around that time, and shown outside of AT&T.

then (1) why was $ adopted so widely?

Because of Motorola's 6800/02/09 line as well as MOS' 6500 series used in many lower-end micro (home) computers. Most notably by Acorn, Apple, Atari and Commodore. Naturally, everyone writing software for these machines/CPUs would use its notation.

Later on, it got enforced by the popularity of the 68000 used, for example, with Atari ST and Commodore Amiga line of machines.

And the opposite, (2) having become ubiquitous for a whole generation of 8 bit programmers,

Now this does very much depend on your 'processor bubble', as it's only true for users of 65xx/68xx based machines. Whoever grew up with an x80 (8080, 8085, Z80) or x86 based machine, like Altair (S100), Tandy TRS-80 and the whole MSX world, will disagree. They'll be quite firm in that a H suffix was the only valid way and everything else is quite exotic :))

why was it abruptly dropped?

It wasn't. There is no worldwide ruling body outclassing it. After all, using either prefix (or suffix) isn't inherent to hex code, but defined by the language used. Motorola/MOS assemblers want a $ prefix, Intel a H suffix, C a 0x prefix and others again want a more mathematics-like prefix of 16# (Ada) or 16r (Smalltalk).

(Not that it matters, but I still use $ when commenting code or scribbling on dead trees.)

And so do many other (*3).

Bottom line: the language one uses defines the notation - and, as always, the first leaves the deepest impression.


Advantage of Prefix over Postfix

Classic mathematics uses a postfix notation of having the radix trailing a number. Which Intel followed with their nnnnH notation. For compiler writing, this brings the downside that a whole word (constant) has to be read first, before it could be decided how to interpret it. This means a buffer is needed holding the whole string, as it can only be converted after advancing until the postfix.

By using a prefix, it's clear from the beginning how to interpret the following characters. This there's no need to buffer (*2). This gives an advantage in parser design and does simplify the assembler a lot. This was especially helpful for fast creation of early cross assembler tools as first bootstrap.


Some History

  • Hex notation was rather uncommon in the early years. Instead, octal was the thing, as most machines were build to a multiple of 3 word size, as well as characters were usually handled as 6 bits.

  • Of the few machines/systems that very early on offered hex, many used various letters/symbols, like the last 6 in the alphabet UVWXYZ (*2), often even non-continuous.

  • IBM introduced a prefixed string format (X'nnnn') with the /360 in 1965

  • Datapoint used octal with a prefixed Zero

  • Intel's 4004 used hex with a suffix of h

  • Intel's 8008 used all octal in manuals and documentation, written as nnnO

  • By 1973, both assemblers were made to use the same B/O/H suffixes.


*1 - Caring for a few bytes of buffer might seam strange today, where the whole source is usually loaded into memory, but RAM was a scare resource back then. As a result, algorithms were preferred that could read data, like from paper tape, and directly work on each symbol read without buffering.

An optimal assembler allows to read any item a character at a time and process it right away with no need to look ahead. Using a prefix supports this.

*2 - A convention often used in engineering when needing symbols.

*3 - Here on RC.SE I try to use notation according to the topic, so $for 65/68, H for Intel, and so on...and when there is no clear relation, I'll fall back to /370 notation x'nn', as that was what I used most, despite having used $ first.

| improve this answer | |
  • 1
    I'm not convinced this answers the question. How did Motorola choose the $? – DrSheldon Aug 16 at 13:57
  • 5
    @DrSheldon In my memory this starts with Motorola (and their engineers) - if you know more, I'd be glad to read and upvote your answer. Mine is about how it came to know and why it changes or not. Why a certain symbol was chosen is always hard to tell, at least unless there are reliable reports from that decision. The same question can be made why they did choose % for binary, @ for octal and ' for character. In the end it doesn't really matter which character it is. The important idea is to use prefix notation to simplify the parser. – Raffzahn Aug 16 at 14:47
  • 1
    … and of course, BBC BASIC used & throughout, possibly inspired by MBASIC's &H – scruss Aug 17 at 0:57
  • 2
    @supercat, exactly. And while we are at it, whoever invented leading 0 as the octal prefix should be shot. It's just mathematical nonsense that 012 must not be exactly equal to 12. – Zeus Aug 17 at 8:04
  • 3
    Pascal (at least the Borland-dervied variants, not sure about others) uses $ too, though I don't know if and how that fits into the history. – Peter Green Aug 17 at 13:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.