|
From: Jonathan S. <gel...@ge...> - 2002-01-23 20:44:54
|
On Tue, 22 Jan 2002, Jonathan Stowe wrote:
> On Tue, 22 Jan 2002, Sam Smith wrote:
> >
> > It appears to be the %b formatting in the sprintf statements.
> >
> > Is there a 5.004 compatible equivalent?
> >
>
> I think that one used to do something funky with unpack :)
>
I had never really had the need to do this in Perl before - does this seem
like a reasonable way of doing it :
for my $foo ( 0 .. 65536 )
{
my $I = 1;
my $out = '';
while($I <= $foo )
{
my $blah = $foo & $I ? 1 : 0;
$out = $blah . $out;
$I *= 2;
}
$out ||= '0';
print "$foo : ", ($out eq sprintf("%b",$foo) ? 'good' : 'bad' ),"\n";
}
You might have noticed I am not a mathematician :)
/J\
--
Jonathan Stowe |
<http://www.gellyfish.com> | This space for rent
|
|