Python- Hex bytearray (b, '\x01\0x2C') 0x2c becomes a comma when added to another byte array

42 Views Asked by At
tempDecimal = 300
if tempDecimal > 255:
    dig1 = tempDecimal // 256
    dig2 = tempDecimal % 256
else:
    dig1 = 0
    dig2 = tempDecimal

dig = (str(dig1) + str(dig2))

# Build hex byte string
hex_str = bytes([dig1, dig2]).hex()
print(hex_str)

tempBytes = bytearray.fromhex(hex_str)
print(tempBytes)

dig1 and dig2 are added as ascii instead of hex

I have been trying for days

0

There are 0 best solutions below