Here is how you encode and decode bytes in python:
>>> '\x41'
'A'
If you want to do this with a function use chr(int()):
chr(65)
'A'
Decode known string:
ord('A')
65
Hex to int:
int('0x41', 16)
65
Int to hex:
hex(65)
'0x41'
题
I do have some problems with python packaging, its generating bytes array from the range of 0x00 to 0xff i suppose, and most of these fall of ascii representation.
I wanna send data in a serial port, few things to be kept in mind is that some of hex values like 0x11 and 0x13 are used by the serial protocol for internal flow control. I need to avoid them by sending.
I can avoid these by sending 2 bytes insted of one, like 0x11 is encoded as 0x7d, 0x31. and 0x13 is encoded as 0x7d, 0x33. This option complicats at receiving end maintain a temprovary byte array and iteratively check for the accurance of 2 string and convert it back to one. - complex
use base64 encoding - simple but only increases the data to 25% more .. i am using RADIO link .. its really hard i dont know what to do .. help me ..!
解决方案
Here is how you encode and decode bytes in python:
>>> '\x41'
'A'
If you want to do this with a function use chr(int()):
chr(65)
'A'
Decode known string:
ord('A')
65
Hex to int:
int('0x41', 16)
65
Int to hex:
hex(65)
'0x41'