Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
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 studying the Monastery: (14)
As of 2015-07-02 22:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (46 votes), past polls