TalkPHP (http://www.talkphp.com/forums.php)
-   Absolute Beginners (http://www.talkphp.com/absolute-beginners/)
-   -   another problem confuse me (http://www.talkphp.com/absolute-beginners/3684-another-problem-confuse-me.html)

 kuigg 11-29-2008 01:41 PM

another problem confuse me

hi,thank the guys solved my preceding puzzle.
now I want to know that why the result of " intval(042); " is 34 but not 42,who can tell me ?

thanks ,

 Salathe 11-29-2008 02:52 PM

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  ```
 Originally Posted by Salathe (Post 20056) 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.