The origin of the `0b[01]*` notation

On twitter, @rsc_ (one of the core developers of Go) tried to find the earliest use of the now pervasive 0b… notation for binary literals. Earliest he found is Camllight in 1994.

Anyone here knows how it got into Camllight? Was it stollen adapted from somewhere else?

3 Likes

Amusing! I played archeologist and found the 0b notation appearing in Caml Light version 0.5, released in September 1992: http://caml.inria.fr/pub/distrib/Oldies/cl5unix.tar.Z, file src/compiler/lexer.mll.

I’m probably the one who introduced this notation in Caml. I can’t remember it took much thinking. I do remember rejecting the 0NNNN notation for octal numbers in C as incomprehensible and a thing from the past. But once you’re committed on 0x for hexadecimal numbers, 0o for octal and 0b for binary follow quite naturally.

As mentioned on the Twitter feed, I may have been influenced by assembly languages that provide a syntax for binary integer literals, even though this syntax is not 0bNNNNN. Indeed, I see that Microsoft’s MASM uses NNNNB, and the x86 assembler I wrote back in 1985 used %NNNNN.

12 Likes