Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^3: decimal to binary

by GrandFather (Saint)
on Jan 09, 2012 at 09:39 UTC ( [id://946970]=note: print w/replies, xml ) Need Help??


in reply to Re^2: decimal to binary
in thread decimal to binary

The key is $dec >>= 1; which shifts $dec one bit right - that is, it moves all the bits one position down and the previous least significant bit "drops off the end". A 0 bit is shifted in as the most significant bit so eventually all the one bits have been shifted out and the while loop ends.

The || !@bits makes sure that there is at least one bit in @bits by executing the loop once when $dec is 0.

I'd guess join and maybe push are new to you. I've provided links to documentation for them.

True laziness is hard work

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2024-04-19 11:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found