Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
3
rated 0 times [  4] [ 1]  / answers: 1 / hits: 81256  / 13 Years ago, thu, july 7, 2011, 12:00:00

What does radix actually means? Why do we need it?



parseInt(10, radixValue); 

More From » javascript

 Answers
195

You might not always want to parse the integer into a base 10 number, so supplying the radix allows you to specify other number systems.



The radix is the number of values for a single digit. Hexidecimal would be 16. Octal would be 8, Binary would be 2, and so on...



In the parseInt() function, there are several things you can do to hint at the radix without supplying it. These can also work against you if the user is entering a string that matches one of the rules but doesn't expressly mean to. For example:



// Numbers with a leading 0 used a radix of 8 (octal) before ECMAScript 5.
// These days, browsers will treat '0101' as decimal.
var result = parseInt('0101');

// Numbers that start with 0x use a radix of 16 (hexidecimal)
var result = parseInt('0x0101');

// Numbers starting with anything else assumes a radix of 10
var result = parseInt('101');

// Or you can specify the radix, in this case 2 (binary)
var result = parseInt('0101', 2);

[#91313] Tuesday, July 5, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
byron

Total Points: 616
Total Questions: 101
Total Answers: 91

Location: Reunion
Member since Wed, Apr 14, 2021
3 Years ago
;