Octals and HexadecimalsQuestion: Is there a way to use octal and hexadecimal numbers in JavaScript? Answer: Yes, in JavaScript you can use octals and hexadecimals. The following are examples of octal numbers: And these are examples of hexadecimal numbers:
When you need to convert an octal or hexadecimal string to a number,
use the function octalStr='377'; num = parseInt(octalStr,8); // num now holds 255 hexStr='7F'; num = parseInt(hexStr,16); // num now holds 127The 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.
See also: |
Copyright © 1999-2012, JavaScripter.net.