Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: A philosophical pondering concerning hexes

by Abigail-II (Bishop)
on Jun 23, 2004 at 10:47 UTC ( #368999=note: print w/ replies, xml ) Need Help??


in reply to A philosophical pondering concerning hexes

Your dec has a problem. Anything matched by /^[0-7]+$/ or /^\d+$/ is going to be matched by /^(0x)?[0-9A-Fa-f]+$/i 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 1016 == 1610, 1010, and 108 == 810 (subscripts indicate base)?

Of course, as pointed out, your fallacy lies in assuming that oct and hex return decimal representations of numbers - they don't. They return numbers:

$ perl -MDevel::Peek -wle 'Dump hex 10' SV = IV(0x8192014) at 0x8181270 REFCNT = 1 FLAGS = (IOK,READONLY,pIOK) IV = 16
It's a number - without a stringified valued.

Also, Perl already has a function to turn a number into a hexadecimal, octal or binary representation: it's called sprintf.

Abigail


Comment on Re: A philosophical pondering concerning hexes
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://368999]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (6)
As of 2015-07-04 20:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (60 votes), past polls