5

I have an array of string-encoded hex values. I need to convert those strings to actual hex values and then be able to compare them (using standard less-than/greater-than/equals). What is the best way to accomplish this?

3 Answers 3

12

Use the JavaScript parseInt method to convert hex string values into their integer equivalent.

For example:

var value = parseInt("FF", 16);
if (value < 256) {
    // do something...
}
4

You can use the parseInt function:

var n = parseInt("10", 16); // parse 10 as base 16 (hex).

-Oisin

2

Use parseInt("0x"+ string) to transform your string value into a numeric one

Not the answer you're looking for? Browse other questions tagged or ask your own question.