Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Power of two round up.

by myocom (Deacon)
on Dec 15, 2000 at 23:54 UTC ( #46903=note: print w/ replies, xml ) Need Help??


in reply to Power of two round up.

More TIMTOWTDI:

for my $foo (1..210) { print "$foo ",dec2bin($foo)," binrounded is ",binround($foo),"\n"; } sub binround { my $bin = dec2bin(shift); my $mod = 0; $mod = 1 if (split('1','0'.$bin.'0') == 2); return '1' . ('0' x (length($bin)-$mod)); } sub dec2bin { my $str = unpack("B32", pack("N", shift)); $str =~ s/^0+(?=\d)//; return $str; }


Comment on Re: Power of two round up.
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (12)
As of 2014-10-31 13:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (217 votes), past polls