Skip to content

Instantly share code, notes, and snippets.

@ghalimi
Last active May 18, 2021 18:26
Show Gist options
  • Save ghalimi/4525548 to your computer and use it in GitHub Desktop.
Save ghalimi/4525548 to your computer and use it in GitHub Desktop.
HEX2DEC Function
// Copyright (c) 2012 Sutoiku, Inc. (MIT License)
function HEX2DEC(number) {
// Return error if number is not hexadecimal or contains more than ten characters (10 digits)
if (!/^[0-9A-Fa-f]{1,10}$/.test(number)) return '#NUM!';
// Convert hexadecimal number to decimal
var decimal = parseInt(number, 16);
// Return decimal number
return (decimal >= 549755813888) ? decimal - 1099511627776 : decimal;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment