I expect you've slapped your forehead by now, but in case you're still scratching it, check this out:
#!/usr/bin/perl -w
use strict;
my @dec_nums = ( 0 .. 255 );
my @hex_nums = ( 0x00 .. 0xFF );
my @oct_nums = ( 000 .. 0377 );
my $msg = "OMG! Inequality among %d. vs. 0x%02X vs. \\%03o on test #%d
+\n";
my $i;
for $i ( 0 .. $#dec_nums ) {
if ( $i != $dec_nums[$i] or $i != $hex_nums[$i] or $i != $oct_nums
+[$i] ) {
die sprintf( $msg, $dec_nums[$i], $hex_nums[$i], $oct_nums[$i]
+, $i );
}
}
if ( @dec_nums != @hex_nums or @dec_nums != @oct_nums ) {
die sprintf( $msg, scalar(@dec_nums), scalar(@hex_nums),
scalar(@oct_nums), $i);
}
printf( "Whew! 0-%d. is the same as 0x00-0x%X and 000-0%o.\n",
pop @dec_nums, pop @hex_nums, pop @oct_nums );
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.