Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re: Script critique requested

by aitap (Deacon)
on Oct 04, 2012 at 17:39 UTC ( #997275=note: print w/ replies, xml ) Need Help??

in reply to Script critique requested

Unfortunately, this is alot easier.

First of all, you could use some loop starting with multiplying a variable by 2, like this:

my $bit = 256; for (1..8) { $bit /= 2; print $dec & $bit; }

Secondly, you can just use pack and unpack instead: print unpack ("B8", (pack "c",$dec)); Explanation: pack the number as a signed char value (0..255) in a byse sequence and unpack as 8 bits.

Sorry if my advice was wrong.

Comment on Re: Script critique requested
Select or Download Code
Replies are listed 'Best First'.
Re^2: Script critique requested
by jhumphreys (Novice) on Oct 04, 2012 at 17:44 UTC

    aitap, thanks for your reply. Am slowly working my way through intro Perl text by Cozens and pack and unpack are coming up. Will study your reply after I learn these.



Log In?

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2015-11-28 00:39 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (735 votes), past polls