Skip to content

Instantly share code, notes, and snippets.

@ghalimi
Created January 13, 2013 19:49
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 ghalimi/4525876 to your computer and use it in GitHub Desktop.
Save ghalimi/4525876 to your computer and use it in GitHub Desktop.
OCT2DEC Function
// Copyright (c) 2012 Sutoiku, Inc. (MIT License)
function OCT2DEC(number) {
// Return error if number is not octal or contains more than ten characters (10 digits)
if (!/^[0-7]{1,10}$/.test(number)) return '#NUM!';
// Convert octal number to decimal
var decimal = parseInt(number, 8);
// Return decimal number
return (decimal >= 536870912) ? decimal - 1073741824 : decimal;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment