Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

mini-golf: convert integer into list of powers of two

by xyzzy (Pilgrim)
on May 23, 2012 at 20:24 UTC ( #972098=perlmeditation: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
             1         2         3         4         5         6         7
    +         8
    1234567890123456789012345678901234567890123456789012345678901234567890
    +1234567890
    sub{$m=sprintf('%b',shift);$n=1;for(reverse split//,$m){$_&&push@v,$n;
    +$n*=2}@v}
    
  2. or download this
             1         2         3         4         5         6         7
    +         8
    1234567890123456789012345678901234567890123456789012345678901234567890
    +1234567890
    sub{for(reverse split//,sprintf('%b',shift)){$_&&push@v,2**$n;$n++}@v}
    

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlmeditation [id://972098]
Approved by BrowserUk
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2021-06-14 21:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What does the "s" stand for in "perls"? (Whence perls)












    Results (65 votes). Check out past polls.

    Notices?