Convert String to Int Base in Python

The int() function in Python converts a string to an integer. But this function has the second default parameter: base. The base can be between 2 (you need to have at least 2 different values) and 36 (numbers + letters). The default value is 10.

Both examples return the same result:

Result:

156
156

This means, by how many elements the value will be represented. Look at the following table to see how it works.

 Base available numbers and letters
 2 01
3012
40123
501234
6012345
70123456
801234567
9012345678
100123456789
160123456789abcdef
200123456789abcdefghij
360123456789abcdefghijklmnopqrstuwvxyz

Now, take a look at the following examples:

All of these lines return the same result, which is 9999.

If you want to convert an integer to binary (2), octal (8), hex (16) or any other base between 2 and 36, you can use the following function.

Now use the following code to display values.

It will return the following result.

10011100001111
111201100
2130033
304444
114143
41103
23417
14640
9999
270f
14jj
7pr