Reputation: 117
I'm writing a code on Python to read information from a RFID, but how I'd left only the hexadecimal part?
Code:
import serial as s
ser = s.Serial('COM8', 9600, timeout=10000)
rfid = ser.read(13).splitlines()
print(rfid)
Output:
[b'\x024500F38EC7FF']
Expected Output:
4500F38EC7FF
Upvotes: 0
Views: 64
Reputation: 19564
If you want just the ASCII characters you can split the string to remove the leading 0x02 character
>>> x = b'\x024500F38EC7FF'
>>> x[1:] # skip the first character
'4500F38EC7FF'
If you want the values of each character as integers,
>>> [ord(c) for c in x]
[2, 52, 53, 48, 48, 70, 51, 56, 69, 67, 55, 70, 70]
Or if you want a hexadecimal representation of each character, you can use something like
>>> ' '.join('%02x' % ord(c) for c in x)
'02 34 35 30 30 46 33 38 45 43 37 46 46'
Upvotes: 1
Reputation: 4559
Because splitlines()
returns you an array, which is what you see on print
Try simply print rfid[0]
, that might do what you want.
>>> x = b'\x024500F38EC7FF'
>>> print(x)
4500F38EC7FF
Upvotes: 1