This is my first entry into CUFP, but I thought this was pretty cool, so I thought I'd go for it.
I'm not sure how many, if any, of you work with wireless phones, or are employed by a wireless company, but if you are out there, you may find this cool. An ESN (Electronic Serial Number) comes in three different formats, Decimal, Hex, and Oct. Well, my company runs two different types of switches, Lucent and Nortel. Nortel uses Decimal ESNs, which are the most commonly used, Lucent on the other hand uses Hex, so we have to have a converter handy to do the math and give us both versions. I have seen an ESN converter in C and in JAVA, but I have never seen one in Perl. So, in good old-fashioned experimentation, I came up with this. It is a simple converter, and a simple script, but it does the job beautifully. Let me know what you think!
UPDATE:I reworked script to work with -w. Look at my home node
Scratchpad for the code.
#!/usr/bin/perl
use strict;
my $hexnum= '00000000';
my $hexnum= $ARGV[0];
my $mfg=hex(substr($hexnum,0,2));
my $serno=hex(substr($hexnum,2,6));
if(length($hexnum) < 8) { &dec }
else { printf("\nDecimal: %d %d\nHex: %s\n\n",$mfg,$serno,$hexnum);
+}
sub dec {
my $decmfg= '00';
my $decserno= '00000000';
my $decmfg= $ARGV[0];
my $decserno= $ARGV[1];
if(length($decmfg) < 3) {printf("Syntax:\n\Dec 000 00000000\nHex 000
+00000\n")}
else {
printf("\nDecimal: %3d %8d\n",$decmfg,$decserno);
printf("Hex: %2X%6X\n\n",$decmfg,$decserno);
}
}
--
Yes, I am a criminal.
My crime is that of
curiosity.
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.