    Next: Example: Numbers Up: Numeric and String Literals Previous: Numeric and String Literals

# Numeric Literals

Numeric literals are frequently used. They represent a number that your program will need to work with. Most of the time you will use numbers in base ten-the base that everyone uses. However, Perl will also let you use base 8 (octal) or base 16 (hexadecimal).

Note: For those of you who are not familiar with non-decimal numbering systems, here is a short explanation. In decimal notation-or base ten- when you see the value 15 it signifies (1 * 10) + 5 or 1510. The subscript indicates which base is being used.

In octal notation-or base eight-when you see the value 15 it signifies (1 * 8) + 5 or 1310.

In hexadecimal notation-or base 16-when you see the value 15 it signifies (1 * 16) + 5 or 2110. Base 16 needs an extra six characters in addition to 0 to 9 so that each position can have a total of 16 values. The letters A-F are used to represent 10-15.
So the value BD16 is equal to (B16 * 16) + D16 or (1110 * 16) + 1310 which is 18910.

If you will be using very large or very small numbers, you might also find scientific notation to be of use. Scientific notation looks like 10.23E+4, which is equivalent to 102,300. You can also represent small numbers if you use a negative sign. For example, 10.23E-4 is .001023. Simply move the decimal point to the right if the exponent is positive and to the left if the exponent is negative.    Next: Example: Numbers Up: Numeric and String Literals Previous: Numeric and String Literals
dave@cs.cf.ac.uk