Use the parseInt Function with a Radix 2019

Tell us what’s happening:

I looked at this and read the description in another topic on this website. So the parseInt function with Radix is to see convert for example time into 60 seconds or 12 into hours. When I look at the problem I do not get it. I see that it has five possible digits in each slot: 10011. What am I doing wrong? Is my reasoning wrong for this problem?

Your code so far


function convertToInteger(str) {
var a = parseInt("10010",5)  
}

convertToInteger("10011");

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/use-the-parseint-function-with-a-radix

So the parseInt function with Radix is to see convert for example time into 60 seconds or 12 into hours

ParseInt convert a string into an integer based on the Numeral System specified. (radix).

Now the next question is, what is a numeral system?
It’s nothing more fancy that a way to express number in a given set manner.

For example:

The decimal systems is a way to express number using the digit from 0 to 9, and is the one we use everyday in our life.

Another famous system is the binary system, where each number is expressed through 0 and 1 only, and is what is used internally by computers.

So according to this

11 // can be "eleven" in decimal

11 // can be "three" in binary.

const n = "11"

parseInt(n, 10) // 11 -> decimal
parseInt(n, 2) // 3 -> binary

Hope it helps :slight_smile:

1 Like

A radix (also called the base) is the number of digits ised in a numbering system: decimal is 10, binary is 2, octal is 8 and so on. parseInt takes a string, and the base of the numbering system, and converts it to a decimal integer. The strong you’ve given it is binary, a numbering system with two digits (0 and 1)

1 Like

so it a parseInt would turn thirteen into 13? is it that basic?

I don’t get how 2 can turn into 3. Also how can 10 be 11 in binary?

No, like

parseInt("101", 10) // "101" is just 101
parseInt("101", 2) // "101" is 5 

I don’t see any correlation between 5 or 101 with 2

what is does mm mean?

Common bases that are not decimal:

Binary

Octal


.
Hexadecimal

1 Like

I get decimals are 10 and binary is 2. How are you getting 5 though?

what are you calculating

The fifth number in the binary numbering system is 101. So if you covert 101 (a binary number) to a decimal integer, which is what parseInt(“101”, 2) does, it’s 5. The binary system only has two numbers, 101 isn’t one hundred and one because one hundred and one isn’t a thing in binary. 101 is the number 101

so 101.00 has 5 digits so the answer is 5. So the answer to the problem in the assignment 10011 is 5 in binary.

No. Firstly 101.00 is not a thing in binary, you can’t have decimal points. 10011 is not the same number as 101, it’s clearly different. It’s not asking you to work it out and write the answer, you just put the number into the parseInt function and tell it that it’s binary and it works it out for you

I saw 101 in decimal form is 101.00. The assignment asks for binary so the answer is 5 since 10011 has five digits in binary.

101 in decimal form is 101. You are completely misunderstanding how number systems work. parseInt lets you convert from different number systems to decimal, you just give it a number, tell it what the base of the system is, and it gives you it back as a decimal (base 10) integer

1 Like

where are you getting five? All I see is 101 which has 3 digits.

It has nothing to do with the number of digits in a particular number. Binary is a number system that uses only two unique digits. Decimal is a number system that uses only 10 unique digits.

1 can still be a decimal number even though it doesn’t have 10 digits. So can 2, 3, 4, 5, 6, 7, 8, 9 10 and so on.

1 can still be a binary number even though it doesn’t have two digits. So can 101, 1101101, and 101111011101

So in any number system, each column of numbers represents that base raised to a power. So in a decimal system, the first column represents 10^0, or ones. The second column is 10^1 or tens. The third, 10^2, or hundreds. In a binary system, the same: the rightmost column is 2^0, or ones, then 2^1 or twos, then 2^2, or fours. So 101 in decimal is 1 in the fours column, zero in the twos column and 1 in the ones column: 4+0+1 = 5.

In fairness, number systems are a complex conversation. And while you COULD use parseInt with a radix of base 60 to convert to minutes, that’s just… hinky.