S2IBase
not ratedConverts string s to an integer. Tolerates leading spaces.
Functions like the native S2I, but it can convert strings with any base between 2 and 36.
First the function trims the string from spaces (mini-StringTrimLeft), and in the same time it checks wether the number has a leading minus-sign. If such a sign is encountered, it is removed and a flag is set. Then the function steps through the number until it encounters the end of the string or a character it doesn't recognize. Then it works its way *backwards* through the string, taking the numerical value of each character and multiplying it with the current slot value (m) and adding it to the output integer (i.) After each character is processed the slot value is multiplied with the base. (So the first "slot" value in a hexadecimal number (base 16) would have the value 1, the second 16, the third 256 etc.) At the end of the function, if the sign flag is set, the function returns the negated output integer. If not, the output integer is returned as is.
Tell me if this makes sense. I doubt it does.
Functions like the native S2I, but it can convert strings with any base between 2 and 36.
First the function trims the string from spaces (mini-StringTrimLeft), and in the same time it checks wether the number has a leading minus-sign. If such a sign is encountered, it is removed and a flag is set. Then the function steps through the number until it encounters the end of the string or a character it doesn't recognize. Then it works its way *backwards* through the string, taking the numerical value of each character and multiplying it with the current slot value (m) and adding it to the output integer (i.) After each character is processed the slot value is multiplied with the base. (So the first "slot" value in a hexadecimal number (base 16) would have the value 1, the second 16, the third 256 etc.) At the end of the function, if the sign flag is set, the function returns the negated output integer. If not, the output integer is returned as is.
Tell me if this makes sense. I doubt it does.