Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Pack decimal possibility

by BrowserUk (Patriarch)
on May 26, 2010 at 21:35 UTC ( [id://841829]=note: print w/replies, xml ) Need Help??


in reply to Pack decimal possibility

pack doesn't support this directly. This will do the job, though it can probably be made significantly more efficient:

sub toComp3{ my $num = shift; my @digits = split'',abs $num; unshift @digits, 0 unless @digits & 1; push @digits, $num < 0 ? 13: 12; my $comp3 = ''; $comp3 .= chr( shift( @digits ) * 16 + shift( @dig +its ) ) while @digits; return $comp3 } print unpack 'H*', toComp3( 240 );; 240c

It also doesn't cover unsigned numbers. Though a flag to indicate signed-ness could be added.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (9)
As of 2024-03-28 10:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found