Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

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.

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 exploiting the Monastery: (4)
As of 2016-10-20 21:34 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (283 votes). Check out past polls.