JavaScript hexdec
Returns the decimal equivalent of the hexadecimal number
1 2 3 4 56 7 8 9 1011 12 13 14 | function hexdec (hex_string) { // Returns the decimal equivalent of the hexadecimal number // // version: 909.322 // discuss at: http://phpjs.org/functions/hexdec // + original by: Philippe Baumann // * example 1: hexdec('that'); // * returns 1: 10 // * example 2: hexdec('a0'); // * returns 2: 160 hex_string = (hex_string+'').replace(/[^a-f0-9]/gi, ''); return parseInt(hex_string, 16); } |
Examples
» Example 1
Running
1 | hexdec('that'); |
Should return
1 | 10 |
» Example 2
Running
1 | hexdec('a0'); |
Should return
1 | 160 |
Dependencies
No dependencies, you can use this function standalone.
Open syntax issues
php.js uses JsLint to help us keep our code consistent and prevent some common bugs.
Eventually we want all code to pass or at least take into consideration most fixes suggested by JsLint, following this JsLint configuration we’ve decided on.
Authors
Thanks to the following developers, you get to have hexdec goodness in JavaScript.
No comments yet. Be the first!
spread the word:
Use any PHP function in JavaScript
These kind folks have already donated: Anonymous and Shawn Houser.
<your name here>