Answers for "base conversion python"

1

python convert base

# add as many different characters as you want
alpha = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"


def convert(num, base=2):
    assert base <= len(alpha), f"Unable to convert to base {base}"
    converted = ""
    while num > 0:
        converted += alpha[num % base]
        num //= base

    if len(converted) == 0:
        return "0"
    return converted[::-1]
  

print(convert(15, 8))  # 17
Posted by: Guest on February-08-2020
0

base conversion python

alpha = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"


def convert(num, base=2):
    assert base <= len(alpha), f"Unable to convert to base {base}"
    converted = ""
    while num > 0:
        converted += alpha[num % base]
        num //= base

    if len(converted) == 0:
        return "0"
    return converted[::-1]
  

print(convert(15, 8))  # 17
Posted by: Guest on March-27-2021
0

base conversion python

Command  Description                          
 -------  -----------                          
 exit     Exit the console                     
 list     List all agents                      
 kill     Kill an agent                        
 run      Run Command and Controler            
 help     Help menu                            
 set      Sets a variable to a value           
 show     Show Command and Controler variables
Posted by: Guest on May-19-2021

Python Answers by Framework

Browse Popular Code Answers by Language