Re: [MacPerl] Re: How can I display a number in dual representation, e.g. 29 --> 11101?

[email protected] (Bruce Van Allen) Sat, 5 Mar 2005 14:05:10 -0800
Newsgroups perl.macperl
Message-ID <r02010400-1038-A4FDD29C8DC211D9AAF9000A2794A806@[192.168.1.100]>
On 2005-03-05 Richard Cook wrote:
>And, don't forget you can use oct to go the other way, if you have the
>0b prefix:
>
>for my $n (0..255){ printf "%d\n", oct sprintf "0b%b", $n;
>}

Good. Maybe you also meant=20
    printf "%b\n", oct ...
             ^
as a way to show the binary value.


>> oct     Interprets EXPR as an octal string and returns the
>> correspond- ing value.  (If EXPR happens to start off with "0x",
>> interprets it as a hex string.  If EXPR starts off with "0b", it is
>> inter- preted as a binary string.  Leading whitespace is ignored in
>> all three cases.)  The following will handle decimal, binary, octal,
>> and hex in the standard Perl or C notation:
>>
>> $val =3D oct($val) if $val =3D~ /^0/;
>
- Bruce

__bruce__van_allen__santa_cruz__ca__