Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: I need Hex conversion, not!

by tobyink (Abbot)
on Jan 07, 2013 at 16:18 UTC ( #1012059=note: print w/ replies, xml ) Need Help??


in reply to I need Hex conversion, not!

This works, but it will give you a slight performance hit. Unless you're doing serious number crunching it'll probably be acceptable...

use strict; use warnings; sub hexnum { package HexNum; use base 'Math::BigInt'; use overload q[""] => 'as_hex'; __PACKAGE__->new(@_); } my $var = hexnum 0x2F; $var += 3; $var += hexnum 0x02; print "$var\n";
perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'


Comment on Re: I need Hex conversion, not!
Download Code
Re^2: I need Hex conversion, not!
by Anonymous Monk on Jan 07, 2013 at 17:17 UTC

    Wow, that is cool. Btw, is there a way to ignore 0x prefix without substr, or anything ?

      use strict; use warnings; sub hexnum { package HexNum; use base 'Math::BigInt'; use overload q[""] => 'as_hex_without_0x'; __PACKAGE__->new(@_); } sub HexNum::as_hex_without_0x { substr($_[0]->as_hex, 2); } my $var = hexnum 0x2F; $var += 3; $var += hexnum 0x02; print "$var\n";
      perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (13)
As of 2015-07-02 08:47 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 (31 votes), past polls