n진수 -> 10진수
int(string, base)
ex) int('thr', 3) #3진법의 문자열 'thr'을 10진수로 변환
- int(3.6) # -> 3. 그냥 뒤에 소수점을 삭제함
10진수 -> 2, 8, 16진수
bin(), oct(), hex() 함수
str = bin(10) #0b0101
str[2:] 라고 적으면 진법이 사라지고 바뀐 수만 출력됨.
10진수 -> n진수
def change(n,q):
chg = ""
while n>0:
n, mod = divmod(n,q)
chg += str(mod)
return chg_[::-1]
n진수->n진수
이건 좀 귀찮더라도 n진수를 10진수로 변환한 후 또 다른 n진수로 변환하면 된다.
'개발공부 > Python 문법' 카테고리의 다른 글
[Python] rjust, ljust() (0) | 2022.01.23 |
---|---|
[Python] isdigit() (0) | 2022.01.20 |
[Python] set() 함수 (0) | 2022.01.18 |
[Python] 문자열 split(), join() (0) | 2022.01.17 |
[Python] 정규 표현식. re모듈 (0) | 2022.01.17 |