I just do not understand why “11” gets converted into an integer of ‘3’ in the following example
var a = parseInt("11", 2);
The radix variable says that “11” is in the binary system, or base 2. This example converts the string “11” to an integer 3.
Your code so far
function convertToInteger(str) {
}
convertToInteger("10011");
I know it says the variable says ‘11’ is part of the binary system, or base 2. Does “11” gets converted into “1” (whole number) and then summed with 2 (system). I just can’t decode this sentence.
by " So, the radix tell the function that 11 is a binary number, which converted to decimal is 3" you mean that “11” is binary because is (“1”+“1”) and converted to a decimal will be a total of 3 numbers [“1” + “1” + (decimalNumber)] ?
The binary numerical system uses only 1 and 0 characters to make its numbers
So, instead of counting 0,1,2,3,4 etc
In binary you count 0,1,10,11,100,101,110,111 etc 11 is the third number of the binary system, so it becomes 3 in the decimal system
Finally someone who goes to the very beginning and explain why without asuming people should know already other things.Bravo for the simple explanation of why parseInt(“11”, 2) returns 3 in base 10! I was googling all over the places and only fancy explanations everywhere.