-3

Can someone please explain what radix is (on the most fundamental level), in reference to parseInt()?

I'm also not understanding how the string argument changes with different bases/radix.

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621
  • 1
    `parseInt()`? *What* `parseInt()`? Which language? Which framework? Please [read about how to ask good questions](http://stackoverflow.com/help/how-to-ask), and also [this question checklist](https://codeblog.jonskeet.uk/2012/11/24/stack-overflow-question-checklist/). – Some programmer dude Aug 03 '18 at 06:56
  • In JavaScript, and I'm just testing in the console atm to try and understand the radix component of it. Eg. why is parseInt(10761, 4) // 4 , whereas parseInt(10761, 8) // 4593 – hitechies Aug 03 '18 at 07:30
  • Possible duplicate of [var functionName = function() {} vs function functionName() {}](https://stackoverflow.com/questions/336859/var-functionname-function-vs-function-functionname) – Gautham Srinivasan Aug 03 '18 at 08:04

1 Answers1

0

Regardless of the language you are using, here is an attempt at a general explanation:

The radix is the base of a numeral system.

Decimal system: radix is 10, therefore 10010 means 100.

Binary system: radix is 2, therefore 1002 means 4.


This is why parseInt(number, radix) needs to know the radix you are working with, so that

parseInt(100, 2)

correctly yields 4 if you're in binary and

parseInt(100, 10)

correctly yields 100 in decimal.


Recommended Reading: Number Systems and Bases

Thomas Flinkow
  • 4,845
  • 5
  • 29
  • 65