Skip to content

Instantly share code, notes, and snippets.

@pfig
Created March 23, 2010 12:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pfig/341110 to your computer and use it in GitHub Desktop.
Save pfig/341110 to your computer and use it in GitHub Desktop.
Convert a decimal integer to hex without using pack().
my @HEX_CHARS = qw( 0 1 2 3 4 5 6 7 8 9 A B C D E F );
my $hex = $HEX_CHARS[($value >> 4) & 0xF] . $HEX_CHARS[($value) & 0xF];
@pfig
Copy link
Author

pfig commented Aug 15, 2011

Slower than pack(), though :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment