ParseInt you don't know

I entered the following code in the console today,
Insert picture description here
Huh? ! Why does it return 1? Isn't this the number 13 is converted to binary and returned?
This aroused my interest, and then I entered the following code
Insert picture description here
Insert picture description here
Insert picture description here
. Why? !
After reading the information, I learned

  • After parseInt receives the parameters, it will parse the first parameter
  • For example, if the first parameter is 345, then divide this number into 3 and 4 and 5.
  • Take 3, 4 and 5 to compare with parameter 2.
  • Parameter 2 is a hexadecimal number, to see if each digit of parameter 1 is within the maximum value of parameter 2
  • For example, the maximum value of binary system is 1, the maximum value of binary system is 2, and so on. The maximum value of parameter 2 is 36
  • If you find that any digit is not within the limit of parameter 2, then don’t look down, just take the first few digits that meet the rules for calculation

Calculation rules
Let ’s go directly to the example
first.
Insert picture description here

  1. Split 46 into 4 and 6

  2. Check if 4 is within the maximum value of hexadecimal (6)

  3. Check whether 6 is within the maximum value of hexadecimal 7

  4. CalculationOperation: 6 times 7 to the power of 0 plus 4 times 7 to the power of 1

  5. Returns 34

2nd
Insert picture description here

  1. Split 99 into 9 and 9
  2. Check if 9 is within the maximum value (4)
  3. There is no number in front of 9 and cannot be calculated
  4. Return NaN

3rd
Insert picture description here

  1. Split 5 and 9 into 5 and 9

  2. Check whether 5 is within the maximum value of hexadecimal (5)

  3. Check whether 9 is within the maximum value of hexadecimal

  4. 9 is not there, just take the number 5 for calculation

  5. Calculation

  6. Insert picture description here

  7. Returns 5

4th
Insert picture description here

  1. Split 2345 into 2, 3, 4, 5
  2. Check if 2 is within the maximum value of hexadecimal (6)
  3. Check whether 3 is within the maximum value of hexadecimal 7
  4. Check if 4 is within the maximum value of hexadecimal 7
  5. Check whether 5 is within the maximum value of hexadecimal
  6. start calculatingInsert picture description here
  7. Return result

Guess you like

Origin blog.csdn.net/m0_47883103/article/details/108352227