Created
June 13, 2010 06:40
-
-
Save yaotti/436412 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
my $hexnum = shift || '0xdeadbeaf'; | |
$hexnum =~ /0x([0-9a-fA-F]+)/ or die 'not hex number'; | |
my $body = $1; | |
my $result = 0; | |
my $cnt = 0; | |
for (reverse split //, $body) { | |
if (/[a-fA-f]/) { | |
tr/a-fA-F/0-50-5/; | |
$_ += 10; | |
} | |
$result += $_ * (16 ** $cnt++); | |
} | |
warn $result; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment