Try to reverse an bytearray(from hex) in python

2.3k views Asked by At

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.

1

There are 1 answers

0
kabr8 On BEST ANSWER

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)