When used with numbers, the toString() method converts a number into a string representation using the base numbering system specified by the optional radix.
For instance the number 8 and toString(2) would return "1000".
Is there a method to achieve the opposite? I.e., convert the string "1000" back into the n开发者_Go百科umber 8?
parseInt()
takes a radix as its second argument, so you can do parseInt("1000", 2)
to get what you want.
You can use parseInt using a raidx 2. i.e
parseInt("1000", 2) will return 8
Check the parseInt() Javascript function: http://www.w3schools.com/jsref/jsref_parseInt.asp
精彩评论