python-3.xhexpython-bytearray

Try to reverse an bytearray(from hex) in python


I have the following script:

hex_string = "c23dba5fcac1048b3c050266ceb6a0e870670021"
hex_bytes = bytearray.fromhex(hex_raw)
print(hex_bytes.reverse())

The problem it prints/returns None. I was wondering, because in this example it works.

Thanks in advance.


Solution

  • I found the issue. The method .reverse() dont return anything, but changes the bytearray, so the code must be:

    hex_string = "c23dba5fcac1048b3c050266ceb6a0e870670021"
    hex_bytes = bytearray.fromhex(hex_raw)
    hex_bytes.reverse()
    print(hex_bytes)