views:

87

answers:

3

How do I alert as FF and not 255 with this:

var myHex1 = 0xff;  
alert(myHex1);//alerts 255


var myVar = 255;
var myHex2 = myVar.toString(16);
alert(myHex2);//also alerts 255 and not FF
+2  A: 

Your second example works for me exactly how it is. Are you sure you're alerting the right variable in your test?

rosscj2533
A: 

Ok it was a string I hadn't parsed to an integer.

Chris_45
A: 

And standard compliant approach is:

var x = 0xFF; window.alert(x.toString(16)); //ff

Regards.

SmashThePain