Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Anyone know why Ken Thompson chose leading 0 for octal in B?

72 views
Skip to first unread message

James Harris

unread,
Aug 27, 2009, 5:56:44 PM8/27/09
to
From a bit of checking I found that BCPL used a leading # for octal.
As far as I can tell the use of a leading zero for octal was
introduced with Ken Thompson's programming language B. There is a
summary of the history at

http://sundry.wikispaces.com/octal-zero-prefix

I wonder if it's possible to add the reasons *why* B used a leading
zero.

Similarly, it looks like Thompson was first to use a leading zero in
this way but there may be other languages that predated B that did the
same. Perhaps those languages influenced B.

Anyone know more?

James

Chris Burrows

unread,
Aug 27, 2009, 7:44:30 PM8/27/09
to
"James Harris" <james.h...@googlemail.com> wrote in message
news:89a1b482-f0fd-4928...@s15g2000yqs.googlegroups.com...

>
> Similarly, it looks like Thompson was first to use a leading zero in
> this way but there may be other languages that predated B that did the
> same. Perhaps those languages influenced B.
>

DEC PDP assembly language? It would make sense.

--
Chris Burrows
CFB Software
Armaide v2.1: ARM Oberon-07 Development System
http://www.armaide.com


Dennis Ritchie

unread,
Aug 28, 2009, 12:50:49 AM8/28/09
to

"James Harris" <james.h...@googlemail.com> wrote in message
news:89a1b482-f0fd-4928...@s15g2000yqs.googlegroups.com...

> From a bit of checking I found that BCPL used a leading # for octal.

In the (original) BCPL manual we had at the time,
http://cm.bell-labs.com/cm/cs/who/dmr/bcpl.html
octal constants
were indicated in the typescript by an initial underlined 8. As we rendered
this in our in our compiler, octal numbers began with a #.

When Thompson did B, he chose to use a leading 0
instead, for reasons of his own.

Dennis


jmfbahciv

unread,
Aug 28, 2009, 8:19:33 AM8/28/09
to
A zero would be easier to type than a #; no shifting involved.

/BAH

James Harris

unread,
Aug 28, 2009, 2:54:43 PM8/28/09
to
On 28 Aug, 05:50, "Dennis Ritchie" <d...@bell-labs.com> wrote:
> "James Harris" <james.harri...@googlemail.com> wrote in message

OK thanks for the info.

James

Rich Alderson

unread,
Aug 28, 2009, 4:24:54 PM8/28/09
to
"Chris Burrows" <cfbso...@hotmail.com> writes:

> "James Harris" <james.h...@googlemail.com> wrote in message
> news:89a1b482-f0fd-4928...@s15g2000yqs.googlegroups.com...

>> Similarly, it looks like Thompson was first to use a leading zero in
>> this way but there may be other languages that predated B that did the
>> same. Perhaps those languages influenced B.

> DEC PDP assembly language? It would make sense.

No, those simply assume octal unless you specify decimal, so no marker for
either is necessary. You simply can't mix different radices on the same line
of code.

Now, in Macro-10/20, there *is* a marker for decimal numbers on a line, an
upparrow (later caret) followed by the letter "D" and the number. Thus, the
two lines of code following produce the same result:

movei 10,1750 ;RIP JSB
movei ^D8,^D1000 ;not nearly as entertaining a comment

though anyone who uses decimal accumulator numbers in Macro-20 code should be
horsewhipped in the public square.

Sometimes using decimal constants makes code much more readable.

--
Rich Alderson "You get what anybody gets. You get a lifetime."
ne...@alderson.users.panix.com --Death, of the Endless

Mike Hore

unread,
Aug 28, 2009, 9:57:34 PM8/28/09
to
Rich Alderson wrote:

>...


> Now, in Macro-10/20, there *is* a marker for decimal numbers on a line, an
> upparrow (later caret) followed by the letter "D" and the number. Thus, the
> two lines of code following produce the same result:
>
> movei 10,1750 ;RIP JSB
> movei ^D8,^D1000 ;not nearly as entertaining a comment

What! In the first line, you have to read the 1750 as *decimal* to make
sense of the comment!!

Cheers, Mike.

---------------------------------------------------------------
Mike Hore mike_h...@OVE.invalid.aapt.net.au
---------------------------------------------------------------

jmfbahciv

unread,
Aug 29, 2009, 8:22:10 AM8/29/09
to
Rich Alderson wrote:
> "Chris Burrows" <cfbso...@hotmail.com> writes:
>
>> "James Harris" <james.h...@googlemail.com> wrote in message
>> news:89a1b482-f0fd-4928...@s15g2000yqs.googlegroups.com...
>
>>> Similarly, it looks like Thompson was first to use a leading zero in
>>> this way but there may be other languages that predated B that did the
>>> same. Perhaps those languages influenced B.
>
>> DEC PDP assembly language? It would make sense.
>
> No, those simply assume octal unless you specify decimal, so no marker for
> either is necessary. You simply can't mix different radices on the same line
> of code.
>
> Now, in Macro-10/20, there *is* a marker for decimal numbers on a line, an
> upparrow (later caret) followed by the letter "D" and the number. Thus, the
> two lines of code following produce the same result:
>
> movei 10,1750 ;RIP JSB
> movei ^D8,^D1000 ;not nearly as entertaining a comment
>
> though anyone who uses decimal accumulator numbers in Macro-20 code should be
> horsewhipped in the public square.


Huh? I wouldn't have thought of doing that in a gazillion years.
Don't tell me somebody actually did that.

>
> Sometimes using decimal constants makes code much more readable.

It also is a definitive method to show intent.

/BAH

Charles Richmond

unread,
Aug 29, 2009, 11:19:59 PM8/29/09
to
Mike Hore wrote:
> Rich Alderson wrote:
>
>> ...
>> Now, in Macro-10/20, there *is* a marker for decimal numbers on a
>> line, an
>> upparrow (later caret) followed by the letter "D" and the number.
>> Thus, the
>> two lines of code following produce the same result:
>>
>> movei 10,1750 ;RIP JSB
>> movei ^D8,^D1000 ;not nearly as entertaining a comment
>
> What! In the first line, you have to read the 1750 as *decimal* to make
> sense of the comment!!
>

It's a "numeric pun"...

--
+----------------------------------------+
| Charles and Francis Richmond |
| |
| plano dot net at aquaporin4 dot com |
+----------------------------------------+

James Harris

unread,
Sep 16, 2009, 6:50:36 PM9/16/09
to
On 28 Aug, 19:54, James Harris <james.harri...@googlemail.com> wrote:

...

> > > I wonder if it's possible to add the reasons *why* B used a leading
> > > zero.
>
> > > Similarly, it looks like Thompson was first to use a leading zero in
> > > this way but there may be other languages that predated B that did the
> > > same. Perhaps those languages influenced B.
>
> > In the (original) BCPL manual we had at the time,
> >    http://cm.bell-labs.com/cm/cs/who/dmr/bcpl.html
> > octal constants
> > were indicated in the typescript by an initial underlined 8.  As we rendered
> > this in our in our compiler, octal numbers began with a #.
>
> > When Thompson did B, he chose to use a leading 0
> > instead, for reasons of his own.
>
> OK thanks for the info.

If anyone's interested or is looking at this later, I've finally got
round to updating the page with the extra information.

http://sundry.wikispaces.com/octal-zero-prefix

James

Dennis Ritchie

unread,
Sep 17, 2009, 1:06:44 AM9/17/09
to

"James Harris" <james.h...@googlemail.com> wrote in message
news:9346a843-6c95-4fef...@v2g2000vbb.googlegroups.com...

On 28 Aug, 19:54, James Harris <james.harri...@googlemail.com> wrote:
> > > I wonder if it's possible to add the reasons *why* B used a leading
> > > zero.

I can push it back a little farther--Ken's assembler for the PDP-7 (before
B)
used the convention. The very original Unix was written in the
GE-635 macro-assembler using macros and cross-assembled;
as soon as possible he wrote his own assembler which did say
010 for 8. It doesn't look like GMAP (previously known as
GEMAP, previously known as GEM) did, though but I could
be wrong--I can't get the whole document about it.

Dennis


Peter Flass

unread,
Sep 17, 2009, 7:04:56 AM9/17/09
to

I don't suppose we can hope that this original source survived?

James Harris

unread,
Sep 17, 2009, 6:46:25 PM9/17/09
to
On 17 Sep, 06:06, "Dennis Ritchie" <d...@bell-labs.com> wrote:
> "James Harris" <james.harri...@googlemail.com> wrote in message

Ah - once we get to assembler level previous assumptions are void! I
remember the PDP-11 assembler assuming all numbers were octal by
default. At the time it didn't seem odd - except that, being an 8- and
16-bit machine I would have preferred hex. Base ten numbers were not
so important then. Funny how times have changed.

I found a manual for the GE machine

http://ed-thelen.org/comp-hist/GE-635.html

As shown in the manual the assembler uses a leading zero for octal.
(Interestingly there's no provision for hex literals.)

I'm not sure what GMAP, GEMAP, GEM are but if I understand correctly
Ken Thompson may have been influenced principally by the GE assembler
to adopt a leading zero - first for his PDP-7 assembler and later for
B.

Did it go something like this?

1964 - GE assembler used leading zero for octal
1969 or before - Ken's PDP-7 assembler uses leading zero
1969 - Unix uses leading zero (at least in some contexts, perhaps)
1971 - B uses leading zero

James

Lee K. Gleason

unread,
Oct 15, 2009, 5:30:03 PM10/15/09
to

>"James Harris" <james.h...@googlemail.com> wrote in message
news:5f984cfb-43ac->4886-8829-7...@p36g2000vbn.googlegroups.com...

>Ah - once we get to assembler level previous assumptions are void! I
>remember the PDP-11 assembler assuming all numbers were octal by
>default. At the time it didn't seem odd - except that, being an 8- and
>16-bit machine I would have preferred hex. Base ten numbers were not
>so important then. Funny how times have changed.

On the PDP-11, having the words chunk three bits per digit makes things
easier to read, since the arguments for most of the instructions are 3 bits
for mode, then 3 bits for register used, present in most of the instruction
formats, encode by three bits. So, for example, ADD -(R3),R0, if I see the
octal form, 064300, I immediately know it's arguments are source, mode 4 R3,
destination mode 0, R0. In hex, 68C0, takes a little more thinking to see
the mode & reg used of both args.
--
Lee K. Gleason N5ZMR
Control-G Consultants
lee.g...@comcast.net


Quadibloc

unread,
Oct 15, 2009, 9:43:45 PM10/15/09
to
On Aug 28, 6:19 am, jmfbahciv <jmfbahciv@aol> wrote:

> A zero would be easier to type than a #; no shifting involved.

My guess would have been that since 0 is a digit, this saved having to
use up an extra character to indicate that a number is octal, and it
could conceivably have saved a machine instruction or two in the code
to process integer constants.

John Savard

0 new messages