in reply to To hex EXPR or 'EXPR' is my question
In the latter two examples, the hex has already been interpreted as a hex value before the hex function is called. So what gets passed to the hex function is the decimal string representation of the number. This may clarify:
$n = 0xaf;; print $n;; 175 print hex $n;; 373 print oct $n;; 125 print hex '175';; 373 print oct '175';; 125
Ie. both hex & oct take strings which they then interpret as numbers in a default base (16 or 8) respectively. If you pass them a number, it is converted to a string first.
But it also gets more confusing as they will also interpret number is each others bases if that is indicated by a prefix in their arguments:
print hex '0x' . '175';; 373 print hex '0' . '175';; 373 print oct '0x' . '175';; 373 print oct '0' . '175';; 125
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: To hex EXPR or 'EXPR' is my question
by JavaFan (Canon) on Nov 07, 2010 at 15:59 UTC | |
|
Re^2: To hex EXPR or 'EXPR' is my question
by biohisham (Priest) on Nov 07, 2010 at 18:07 UTC | |
by BrowserUk (Patriarch) on Nov 07, 2010 at 18:44 UTC |