No such thing as a small change | |
PerlMonks |
Re^3: decimal to binaryby GrandFather (Saint) |
on Jan 09, 2012 at 09:39 UTC ( [id://946970]=note: print w/replies, xml ) | Need Help?? |
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
In Section
Seekers of Perl Wisdom
|
|