Skip to content

Instantly share code, notes, and snippets.

@yaotti
Created June 13, 2010 06:40
Show Gist options
  • Save yaotti/436412 to your computer and use it in GitHub Desktop.
Save yaotti/436412 to your computer and use it in GitHub Desktop.
#!/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