Just another Perl shrine | |
PerlMonks |
comment on |
( [id://3333]=superdoc: 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 reply to Re^3: decimal to binary
by GrandFather
|
|