진수 변환

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 출력

'코딩테스트 > 메모' 카테고리의 다른 글

[자바스크립트] 집합(초집합, 합집합, 교집합, 차집합, 멱집합)  (0) 2023.05.17
집합  (0) 2022.11.08
  (0) 2022.11.08
소인수분해  (0) 2022.10.19
피보나치 수  (0) 2022.10.13

BELATED ARTICLES

more