- Home /
Question by
Coldercraft · May 24, 2015 at 02:42 PM ·
convertdecimalhex
Convert Hexadecimal to Decimal JS
I am trying to convert a hexadecimal number in string format to a decimal.
Debug.Log(parseInt(hexInput,16).ToString(10));
The error says:
Please could you help me to either work around this or tell me what I am obviously doing wrong, I would be very grateful.No appropiate version of 'UnityScript.Lang.UnityBuiltins.parseInt' for the argument list '(String,int)' was found.
Comment
Best Answer
Answer by maccabbe · May 24, 2015 at 02:48 PM
Sorry, missed the JS. Here is an example of int to hex and back
#pragma strict
import System.Globalization.NumberStyles;
function Start ()
{
var startNumber : int = 10;
var hexString : String = System.Convert.ToString(startNumber, 16);
print(hexString);
var yourNumber : int = System.Int32.Parse( hexString, System.Globalization.NumberStyles.AllowHexSpecifier );
print(yourNumber);
}
(as far as I can tell, parseInt in unityscript is just another name for int.parse and can only be used for string->int, unlike in real javascript)