Octals and Hexadecimals
The following are examples of octal numbers:
Positive octal numbers must begin with
0 (zero) followed by octal digit(s).
Negative octal numbers must begin with
-0 followed by octal digit(s).
And these are examples of hexadecimal numbers:
Positive hexadecimals must begin with
and negative hexadecimals must begin with
When you need to convert an octal or hexadecimal string to a number,
use the function
parseInt(str,base). Consider these examples:
num = parseInt(octalStr,8); // num now holds 255
num = parseInt(hexStr,16); // num now holds 127
The second argument of
parseInt specifies the base of the number
whose representation is contained in the original string. This argument
can be any integer from 2 to 36.
Converting numbers to another base