Octal value (Definition)

A numeric value based on a radix of 8.

Availability:

ECMAScript edition - 3

An octal value is an integer composed of only the following characters:

0 1 2 3 4 5 6 7

Octal values are always prefixed by a zero character.

The sequence carries over for the next increment when each column reaches the value 7. Thus:

00 01 02 03 04 05 06 07 010 011 012

Octal values have a historical significance from having been used in the earliest computer systems. However these days, they are particularly useful since they map quite conveniently to the binary system. Each octal digit corresponds to three binary digits.

The most significant of the three octal digits does not have a full range since it contains a carry over bit and a three digit octal number actually represents a 9 bit value. However, an 8 bit value can be encoded conveniently if the range is limited to 0377 as a maximum. Hexadecimal values map far more conveniently although they are harder to compute mentally.

Warnings:

Example code:

   <HTML>
   <HEAD>
   </HEAD>
   <BODY>
   <SCRIPT>
   myString = "00123";
   document.write(stripLeadingZeros(myString));
   // Strip leading zero characters off a numeric string
   function stripLeadingZeros(aString)
   {
      return aString.substr(aString.search(/[1-9]/));
   }
   </SCRIPT>
   </BODY>
   </HTML>

See also:Decimal value, Hexadecimal value, Integer constant, Number, Number.toString()

insert figure 0037

Cross-references:

ECMA 262 edition 3 - section - B.1

O'Reilly JavaScript Definitive Guide - page - 35