View Single Post
Old 11-29-2008, 02:52 PM   #2 (permalink)
Salathe
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

The number 042 is an octal number (base 8) rather than a 'normal' decimal number (base 10). It's the octal 42 which can be explained below:

Octal
Code:
32 16  8  1
-  -   4  2
To work out the decimal value, multiply the header line by the digit line and sum those values. 8*4 + 1*2 which gives 34.

Compare this to decimal numbers
Code:
1000 100 10  1
-    -   4   2
Multiplying the values together again: 10*4 + 1*2 which gives 42.

You can also use hexadecimal (base 16) by preceding the number with 0x. For example, all of the following have an integer value of 123.

PHP Code:
$num 123;  // decimal
$num 0x7B// hexadecimal
$num 0173// octal 
More information can be found on the integers PHP manual page.
Salathe is offline  
Reply With Quote