파이썬[Python]: 내장함수 - from_bytes 메서드
파이썬(Phthon): int 클래스 - from_bytes 메서드(method)
/// 설명
주어진 바이트 배열에 대한 정수를 반환합니다.
※ 형식
classmethod int.from_bytes(bytes, byteorder, *, signed=False)
※ 형식
classmethod int.from_bytes(bytes, byteorder, *, signed=False)
/// 예제
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | # b'\x00d', b'\x03\xe8', b"'\x10" # 'big' byteorder # the most significant byte is at the beginning of the byte array. print(int.from_bytes(b'\x00d', byteorder='big')) # 100 print(int.from_bytes(b'\x03\xe8', byteorder='big')) # 1000 print(int.from_bytes(b"'\x10", byteorder='big')) # 10000 print(int.from_bytes(b'\x27\x10', byteorder='big')) # 10000 print('-' * 20) # 'little' byteorder # the most significant byte is at the end of the byte array. print(int.from_bytes(b'\x00d', byteorder='little')) # 25600 print(int.from_bytes(b'\x03\xe8', byteorder='little')) # 59395 print(int.from_bytes(b"'\x10", byteorder='little')) # 4135 print(int.from_bytes(b'\x27\x10', byteorder='little')) # 4135 print('-' * 20) # -10000(2'complement) -> b'\xd8\xf0' print(int.from_bytes(b'\xd8\xf0', byteorder='big', signed=True)) # 55536's array of bytes -> b'\xd8\xf0' print(int.from_bytes(b'\xd8\xf0', byteorder='big', signed=False)) print('-' * 20) # using a list print(int.from_bytes([1, 0, 0], byteorder='big')) # 65536 print('-' * 20) # List(array of bytes) test = bytes([1]) print(test) # b'\x01' test = bytes([1, 0]) print(test) # b'\x01\x00' test = bytes([1, 0, 0]) print(test) # b'\x01\x00\x00' test = bytes([1, 0, 0, 0]) print(test) # b'\x01\x00\x00\x00' | cs |
* 실행환경: Microsoft Windows 10 Homes
* 인터프리터: 파이썬(Python 3.9)
– 당신을 응원합니다. –
댓글
댓글 쓰기