in reply to Ascii Table

I use the following little script:
#!/usr/bin/perl -w use HTML::Entities; @chr=qw(NUL SOH STX ETX EOT ENQ ACK BEL BS HT NL VT NP CR SO SI DLE DC1 DC2 DC3 DC4 NAK SYN ETB CAN EM SUB ESC FS GS RS US SP); printf("DEC\tHEX\tOCT\tBIN \tCHR\tHTML\n"); printf("---\t---\t---\t--------\t---\t----\n"); for (0..255) { printf("%.3u\t%.2x\t%.3o\t%.8b\t%s\t%s\n", $_,$_,$_,$_,$_<33?$chr[$_]:chr($_),$_<33?"":encode_entities(chr($_ +))); }
Prints ascii characters or mnemonics, dec,hex,oct and bin values plus the html encoded value.

/brother t0mas

Replies are listed 'Best First'.
Re: Re: Ascii Table
by cei (Monk) on Dec 06, 2000 at 00:12 UTC
    Hmm. I'm getting an invalid conversion on the %b...
      The %b conversion for printf wasn't added until perl5.6.0. For earlier versions, you can convert decimal to binary with pack and unpack:
      $binary = unpack 'B*', pack 'N', $decimal; $binary =~ s/^0+//;
      Strange...
      Can you do any %b conversions at all?
      Like perl -e "printf('%b",20');" ?

      /brother t0mas