Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

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]
[Corion]: :-D
[Discipulus]: i was kidding.. and i was kidded:perl -lne " if (length $_ > $l){$l=length $_;$w=$_}}{print qq($w $l\n)" linux.words

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2017-10-18 08:13 GMT
Find Nodes?
    Voting Booth?
    My fridge is mostly full of:

    Results (243 votes). Check out past polls.