<?xml version="1.0" encoding="windows-1252"?>
<node id="368999" title="Re: A philosophical pondering concerning hexes" created="2004-06-23 06:47:55" updated="2005-08-10 22:18:44">
<type id="11">
note</type>
<author id="169744">
Abigail-II</author>
<data>
<field name="doctext">
Your &lt;tt&gt;dec&lt;/tt&gt; has a problem. Anything matched by &lt;code&gt;/^[0-7]+$/&lt;/code&gt; or &lt;code&gt;/^\d+$/&lt;/code&gt; is going to be
matched by &lt;code&gt;/^(0x)?[0-9A-Fa-f]+$/i&lt;/code&gt; as well, so if you
do the tests in order you present it, it'll assume either hexadecimal, or binary. Reversing the order will give a problem as well. How would you distinguish between &lt;tt&gt;10&lt;sub&gt;16&lt;/sub&gt; == 16&lt;sub&gt;10&lt;/sub&gt;&lt;/tt&gt;, &lt;tt&gt;10&lt;sub&gt;10&lt;/sub&gt;&lt;/tt&gt;, and &lt;tt&gt;10&lt;sub&gt;8&lt;/sub&gt; == 8&lt;sub&gt;10&lt;/sub&gt;&lt;/tt&gt; (subscripts indicate base)?
&lt;p&gt;
Of course, as pointed out, your fallacy lies in assuming that &lt;tt&gt;oct&lt;/tt&gt; and &lt;tt&gt;hex&lt;/tt&gt; return decimal representations of numbers - they don't. They return &lt;em&gt;numbers&lt;/em&gt;:
&lt;code&gt;
    $ perl -MDevel::Peek -wle 'Dump hex 10'
    SV = IV(0x8192014) at 0x8181270
      REFCNT = 1
      FLAGS = (IOK,READONLY,pIOK)
      IV = 16
&lt;/code&gt;
It's a number - without a stringified valued.
&lt;p&gt;
Also, Perl already has a function to turn a number into a hexadecimal, octal or binary representation: it's called &lt;tt&gt;sprintf&lt;/tt&gt;.
&lt;p&gt;
Abigail
</field>
<field name="root_node">
368936</field>
<field name="parent_node">
368936</field>
</data>
</node>
