Javascript opposite toString ()?

When used with numbers, the toString () method converts a number to a string representation using the underlying numbering system specified by the optional base.

For example, the number 8 and toString (2) will return "1000".

Is there a way to achieve the opposite? Ie, convert the string "1000" back to the number 8?

+7
source share
3 answers

parseInt() takes a radix value as the second argument, so you can do parseInt("1000", 2) to get what you want.

+13
source

You can use parseInt using raidx 2. i.e.

 parseInt("1000", 2) will return 8 
+10
source

Check out the parseInt () Javascript function: http://www.w3schools.com/jsref/jsref_parseInt.asp

+3
source

All Articles