Last active
May 18, 2021 18:26
-
-
Save ghalimi/4525548 to your computer and use it in GitHub Desktop.
HEX2DEC Function
This file contains 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
// 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