When I am running this function the value is showing up as 26. I want to know what calculation the system uses and why it is evaluating to 26.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>parseint</title>
<script type="text/javascript">
var par= "1a";
alert (parseInt(par,16))
</script>
</head>
<body>
</body>
</html>
The second argument of
parseIntis the radix. It shows what base to use. Base 16 is hexadecimal, and1ain base 16 is26in base 10 (decimal).This is why it’s important to always specify the radix when using
parseInt. In this case, not supplying the radix will result in the value1, because it attempts to parse the number in base 10, gets to the charactera, gives up and returns what it has found so far:However, if the number begins with the characters
0xor0X, it is assumed to be a hexadecimal number, and you can omit the radix (although it’s recommended to always pass the radix to avoid unwanted side effects):