note
jynx
beware before!<p>
Yesterday i found an amusing little routine to do decimal to binary (not the same drek everyone did in school as i understand it). So i converted it to perl and felt like posting it. Unfortunately i may have messed up something, so if someone (like maybe [IO]) could tell me if i did or not that would be sweet.<code>
sub dec2bin {
my $num = shift;
my @num; my $i = 0;
(push @num, (($num & 2**$i) == 2**$i) ? 1 : 0) and $i++ until (2**$i > $num);
return 0 + join '', reverse @num;
}
</code>
It is completely untested, but it should work (as if that's any boon to a programmer)<p>
jynx<p>
<b>update:</b> changed the <code>$n</code> to <code>$num</code> on line 5 according to [IO]'s [54690|suggestion] (thank you).
54317
54317