Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

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
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.

    Best,

    J.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (7)
As of 2014-09-20 16:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (160 votes), past polls