Looks like you want parseInt . It takes a string and an optional radius (which should always be supplied), and analyzes the number as an integer in this radix (or based on a format-based number if none are supplied, so you should always supply one, people are surprised to find that parseInt("010") returns 8 ).
> parseInt("ab", 16) 171
To convert back to hex, you can use toString :
> var num = 16 > num.toString(16) "10"
Note that you will need to put it on two characters yourself if it comes out as only one character:
> num = 5 > num.toString(16) "5"
I was bored, so I wrote some functions to convert in both directions:
function parseHexString(str) { var result = [];
What can be used as follows:
> parseHexString("abcd100001") [171, 205, 16, 0, 1] > createHexString([0, 1, 2, 10, 20, 100, 200, 255, 1000, 2000]) "0001020a1464c8ffe8d0" > parseHexString(createHexString([0, 1, 2, 10, 20, 100, 200, 255, 1000, 2000])) [0, 1, 2, 10, 20, 100, 200, 255, 232, 208]