[Python] Hex string to Int, bytes와 bytearray 활용
파이썬으로 시리얼통신을 구현할 때 필요했던 부분을 메모 1. 4바이트 헥사문자열을 10진수 아스키 문자열로 변환하기 2. 아스키 문자열의 길이가 10자리가 되지 않는다면 0(0x30)으로 채우기 3. 패킷데이터 변경이 필요한 버퍼는 bytearray로 사용하기 hexstr = "1a2b3c4d" # Hex String to Int dec = int(hexstr, 16) print(dec) # 10자리 문자열로 변환 (10자리가 안되면 0으로 채우기) decstr = format(dec, '010') print(decstr) data = bytes(decstr, encoding="utf-8") # 변경할 수 없는 배열 print(data) sendbuffer = bytearray([0x02, 0x30, 0..
개발/Python
2022. 3. 15. 14:17
반응형
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- sms api
- setTimeout
- Android Bar Color
- 어바니엘
- AlertDialog
- Naver Cloud Platform
- ProgressBar
- Window Status Bar
- Shell Script
- 롯데캐슬
- 루미니
- clearTimeout
- Bad mode in Synchronous Abort handler detected
- viewDidAppear()
- 다트 플러터
- SHORT URL
- action bar
- whose view is not in the window hierarchy
- wsl lsblk
- Nginx #NodeJS #웹서버 #포트포워딩 #웹호스팅 #백엔드개발 #웹개발 #웹프로젝트 #서버관리 #웹애플리케이션
- viewDidLoad()
- USB Mass Storage
- raspberrypi serial
- artik710
- wsl usb mount
- usbipd attach
- Dart Flutter
- sms
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
글 보관함