728x90
struct라는 내장 모듈을 활용한다!!
import sturct
a = 34531
byte_a = struct.pack('<i', a)
------------
byte_a : b'\xe3\x86\x00\x00'
< 는 little-endian 방식을 의미한다.
그 뒤의 문자는 데이터 타입을 의미한다.
https://docs.python.org/3/library/struct.html
struct — Interpret bytes as packed binary data — Python 3.10.1 documentation
struct — Interpret bytes as packed binary data Source code: Lib/struct.py This module performs conversions between Python values and C structs represented as Python bytes objects. This can be used in handling binary data stored in files or from network c
docs.python.org