justintime has asked for the wisdom of the Perl Monks concerning the following question:
'Executing mac2int.pl 001095123456' results in:sub mac2long { my @mac = unpack("A4"x3,shift); my $long = 0; foreach my $octet (@mac) { $long <<= 16; $long |= hex($octet); } $long; } sub long2mac { my $long = shift; my @octets; for (my $i = 2; $i >= 0; $i--) { $octets[$i] = sprintf("%04x",($long & 0xFFFF)); $long >>= 16; } join('.',@octets); } chomp(my $inmac = shift @ARGV); my $long = mac2long($inmac); print "$inmac converted to long: $long\n"; my $outmac = long2mac($long); print "$long converted to mac: $outmac\n";
For the life of me, I can't figure out why I can't get the last remaining octet back. Anyone have any tips? Justin001095123456 converted to long: 2500998230 2500998230 converted to mac: 0000.9512.3456
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Help with Mac Address to Integer conversion
by ikegami (Patriarch) on Mar 18, 2005 at 18:33 UTC | |
by ikegami (Patriarch) on Mar 18, 2005 at 19:15 UTC | |
|
Re: Help with Mac Address to Integer conversion
by DrHyde (Prior) on Mar 21, 2005 at 09:39 UTC | |
| A reply falls below the community's threshold of quality. You may see it by logging in. |