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

Thank you grandfather for the tips. You have used some keywords unknown to me but are self explainable. But I didn't understand the logic for converting decimals greater than 256. I just started the Perl for beginners ..

Replies are listed 'Best First'.
Re^3: decimal to binary
by GrandFather (Saint) on Jan 09, 2012 at 09:39 UTC

    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