base conversion python

Solutions on MaxInterview for base conversion python by the best coders in the world

showing results for - "base conversion python"
Errol
11 Sep 2019
1# add as many different characters as you want
2alpha = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
3
4
5def convert(num, base=2):
6    assert base <= len(alpha), f"Unable to convert to base {base}"
7    converted = ""
8    while num > 0:
9        converted += alpha[num % base]
10        num //= base
11
12    if len(converted) == 0:
13        return "0"
14    return converted[::-1]
15  
16
17print(convert(15, 8))  # 17
Mellina
29 Jan 2018
1alpha = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
2
3
4def convert(num, base=2):
5    assert base <= len(alpha), f"Unable to convert to base {base}"
6    converted = ""
7    while num > 0:
8        converted += alpha[num % base]
9        num //= base
10
11    if len(converted) == 0:
12        return "0"
13    return converted[::-1]
14  
15
16print(convert(15, 8))  # 17
Céline
29 Nov 2020
1
2 Command  Description                          
3 -------  -----------                          
4 exit     Exit the console                     
5 list     List all agents                      
6 kill     Kill an agent                        
7 run      Run Command and Controler            
8 help     Help menu                            
9 set      Sets a variable to a value           
10 show     Show Command and Controler variables 
11
queries leading to this page
base conversion pythonpython to basepython program convert a base 4 number to base 16 directlyconvert bases pythonsimple python program to convert decimal to base 16 representationconvert to any base pythonconvert base pythonbase conversion in pythonpython convert to base 62base convertor code for pythonbase convert pythonhow to convert base 10 to base 2 in pythonchange base pyhton convert base in pythonbase converter python8 to base 2 notation pythonconvert a decimal number to a number of a given base b pythonconvert number in base 7 using pythonhow to change the base of a number in pythonhow to convert base in pythonpython base 10 to base 16how to convert base pythonconvert base 10 to base 2 pythonfrom python basehow to change base system in pythonbase n coding in pythonprogram to convert number between bases pythonconvert to base pythonpython convert to base 16how to do base conversion in pythonpython base conversionhow to change number base in pythonbase conversions in pythomhow to convert bases in pythonsetting base for binary pythonpython base converterhow to do base in pythonany base to any base conversion in pythonconvert to base 36 pythonconvert bases in pythonpython change to base 2base converter python codebase 10 to base 16 pythonconvert from base 10 to base 20 pythonbase 10 to base 2 python converterconvert any base to any base in pythonhow to convert between bases in pythonpython convert baseconverting decimal to base 7 using stack pythonpython base converter codebase conversion program pythonpython base x number to decimal conversionwrite a program that converts decimal integers into a given base pythonchange a base 10 to a base 2 pythonpython convert to base 10convert between bases pythonconvert text to a different base in pythonconvert a number to nay base in pythonconverting base 10 to base 2 pythonpython convert base45base 20 to base 2 in pythonpython convert basesbase conversion python