2진수, 8진수, 16진수

Changyeol Choi·2021년 1월 31일
0

Python

목록 보기
3/4
>>> a = 23
>>> b = 0o23
>>> c = 0x23
>>> d = 0b1010
>>> print (a, b, c, d)
23 35 19 10

내장함수

>>> bin(42)
'0b101010'
>>> oct(42)
'0o52'
>>> hex(42)
'0x2a'

format()

>>> value = 60
>>> a = format(value, 'b')
>>> b = format(value, 'o')
>>> c = format(value, 'x')
>>> print (a,b,c)
111100 74 3c

2,8,16진수에서 10진수로 변환

>>> int('0b101010', 2)
42
>>> int('0o52', 8)
42
>>> int('0x2a', 16)

예제

>>> value = 60
>>> b = hex(value)
>>> c = format(value, 'x')
>>> int (c, 16)
60
>>> int (b, 16)
60
>>> print (b,c)
0x3c 3c
>>>

진법 변환

>>> o = oct(0b1010)
>>> h = hex(0b1010)
>>> s = str(0b1010)
>>> print (o,h,s)
0o12 0xa 10
>>>
profile
10년 후...내 모습을 위한 첫걸음

0개의 댓글