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

Re: Extract numbers in multiple bases

by MrNobo1024 (Hermit)
on Oct 15, 2001 at 02:38 UTC ( #118784=note: print w/ replies, xml ) Need Help??


in reply to Extract numbers in multiple bases

sub jcwren { my $num = shift; my($ok, $base, $value); if($num =~ m/^0x([\dA-Fa-f]+)$/s or $num =~ m/^([\dA-Fa-f]+)h$/s) { $ok = 1; $base = 16; $value = hex($1); } elsif($num =~ m/^([0-7]+)o$/s) { $ok = 1; $base = 8; $value = oct($1); } elsif($num =~ m/^([+-]?(?=\d|\.\d)\d*(?:\.\d*)?(?:[Ee](?:[+-]?\d+))? +)t?$/s) { $ok = 1; $base = 10; $value = 0 + $1; } else { $ok = 0; $base = 0; $value = 0; } return($ok, $base, $value); }


Comment on Re: Extract numbers in multiple bases
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (13)
As of 2015-07-06 22:12 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 (83 votes), past polls