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 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 = oct($val) if $val =~ /^0/; > - Bruce __bruce__van_allen__santa_cruz__ca__