진수 변환
2022. 11. 8. 12:23
10진수 -> base진수
def convert_notation(n, base):
T = '0123456789ABCDEF'
quotient, remainder = divmod(n, base)
return convert_notation(quotient, base) + T[remainder] if quotient else T[remainder]
16진수까지 변환 가능한 함수.
base진수 -> 10진수
int('문자열', base)
n진수로 표현된 문자열과 n을 매개변수로 주면 10진수로 변환한 값이 출력됨.
ex) int('11', 2) -> 3 출력 / int('222', 3) -> 26 출력