Skip to content

Instantly share code, notes, and snippets.

Last active May 18, 2021 18:26
What would you like to do?
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