7

I was reading the user manual for an old program "UNRAVEL": http://www.ml1.org.uk/pdf/Unravel_User_Manual_1971.pdf. On page 9, it describes the syntax for integer constants:

Unsigned integers may be used as constants. If the integer starts with the digit zero it is evaluated to the machine base; otherwise it is taken as decimal. Thus, for example, on an octal machine 077 would be the same as 63 and on a hexadecimal machine 0A9 (where A means ten) would be the same as 169.

I am aware of different word sizes, but what is the point in interpreting an integer literal differently depending on the machine? Was this practice common back in the day?

2
  • Hm, the language UNRAVEL looks suspiciously similar to BASIC ...
    – dirkt
    Commented Aug 2, 2020 at 15:11
  • I'm not aware that any 'octal machines'or 'hexadecimal machines' were ever built, although certainly the PDP-11 preferred octal in its utilities.
    – user207421
    Commented Aug 3, 2020 at 10:13

1 Answer 1

10

I believe that the intent is that, since UNRAVEL is intended as a tool for building raw-memory interpretation programs (dump analyzers), then the main use of non-decimal notation would be to interpret memory content at the level of a field within a word, possibly even a single bit.

Given the state of art at the time, such interpretation would be specific to a given machine (and OS). And you'd likely be copying your bit/field definitions from the native software - there probably were not "header files" you could just use.

It's convenient for doing this copying to be able to express your definitions in whatever base the machine in question used. Or, more precisely, whatever base was conventionally used for software and documentation for that machine.

It seems a little strange to be using one notation to denote different numbers, rather than providing explicit indicators for octal, hex, and binary, but there was probably no practical drawback.

(This is theorizing, I have never seen the program before)

It's interesting that they have the same 'leading 0 is a different base' convention as C and Unix. I wonder if that's where they got the notion from? I never saw it anywhere before C.

5
  • 2
    I once saw a weird Java bug related to a leading 0. One developer liked to make his code line up neatly so in a switch, he prefixed some numbers with 0 to make them them the same length as longer ones.
    – badjohn
    Commented Aug 3, 2020 at 8:35
  • 3
    IMO it was a mistake to copy that C-ism into Java. There was some justification for the simplicity of writing (e.g.) 077 when octal was the only non-decimal base the language authors cared about, but the notation should have been retired long ago. There are plenty of other ways to denote a radix.
    – dave
    Commented Aug 3, 2020 at 12:27
  • Yes, I was very surprised to find it in C. I can remember systems where octal was used but I don't know of any which were still commonly used by the time that Java was invented.
    – badjohn
    Commented Aug 3, 2020 at 12:34
  • Speculation: using a leading 0 as a mnemonic for O, when 0 was already a valid character in a literal, probably simplified the lexer back when every byte was at a premium. (This theory assumes that this particular idiom predates hexadecimal literals, which would have introduced 7-14 new characters.)
    – chepner
    Commented Aug 3, 2020 at 13:22
  • An octal machine represents a byte as 6-bits. As such octal numbers are more convenient to use. A hexadecimal machine has an 8-bit byte. We have settled on the 8-bit byte. Commented Aug 19, 2020 at 10:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .