반응형 int형을 2byte배열로2 [Python] int정수형을 2byte 배열로 변환 파이썬에서 int형 정수를 byte로 변환하는 코드 def get2Byte_Int(self,data): convertBytes = bytearray(2) convertBytes[0] = ((data>>8) & 0x000000ff) convertBytes[1] = (data & 0x000000ff) return convertBytes 결과를 확인 하는 코드를 작성한다 class Test: def get2Byte_Int(self,data): convertBytes = bytearray(2) convertBytes[0] = ((data>>8) & 0x000000ff) convertBytes[1] = (data & 0x000000ff) return convertBytes def __init__(self): pr.. 2021. 8. 2. int형 정수를 2byte 배열로 변환 int형 정수를 2byte로 변환하기 위한 코드 public static byte[] get2Byte_Int(int data) { byte[] convertBytes = new byte[2]; convertBytes[0] = (byte)((data >> 8) & 0x000000FF); convertBytes[1] = (byte)(data & 0x000000FF); return convertBytes; } 결과 확인용 프로그래밍 코드 public static void main(String[] args) { int data = 5; byte[] bdata = get2Byte_Int(data); for (int i =0;i 2021. 7. 2. 이전 1 다음 반응형