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

Re: Re(golf): I'm looking for the faster way to convert char 2 Bin and Bin 2 char (8bits)

by I0 (Priest)
on Jan 27, 2001 at 05:08 UTC ( [id://54690]=note: print w/replies, xml ) Need Help??


in reply to Re(golf): I'm looking for the faster way to convert char 2 Bin and Bin 2 char (8bits)
in thread I'm looking for the faster way to convert char 2 Bin and Bin 2 char (8bits)

Testing it would have found
Name "main::n" used only once: possible typo at - line 5.
But besides that, ** is a more expensive operation than you need here especially doing it 3 times per iteration.
using 1<<$iin place of 2**$i would be a bit faster.
my $i = 1; (push @num, (($num & $i) ? 1 : 0)) and $i<<=1 until $i > $num;
is even better. And
(push @num, (($num & 1) ? 1 : 0)) and $num>>=1 until 1 > $num;still faster...
  • Comment on Re: Re(golf): I'm looking for the faster way to convert char 2 Bin and Bin 2 char (8bits)
  • Select or Download Code

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2024-04-20 16:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found