Python Forum
Value error when converting hex value to bytearray
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Value error when converting hex value to bytearray
#4
input_hex = '08 22 1 0 1 0 D4'

# you can strip the white spaces, but the number of hex values have to be even.
data = bytearray.fromhex(input_hex.replace(' ', ''))
print(data)
Output:
bytearray(b'\x08"\x10\x10\xd4')
If you are using groups, you have to be consistent. Always two hex values have to be grouped together, if white space is used.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Messages In This Thread
RE: Value error when converting hex value to bytearray - by DeaD_EyE - Mar-01-2019, 08:29 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  send bytearray over UART trix 9 1,592 Sep-30-2024, 01:08 PM
Last Post: trix
  bytearray weirdness or newbee newness Curbie 3 1,087 Sep-18-2024, 01:25 AM
Last Post: deanhystad
  appending to a bytearray Skaperen 21 33,481 Mar-19-2023, 11:05 PM
Last Post: Skaperen
  Split Bytearray into separate Files by Hex delimter lastyle 5 6,464 Mar-09-2023, 07:49 AM
Last Post: bowlofred
  Save multiple Parts of Bytearray to File ? lastyle 1 1,553 Dec-10-2022, 08:09 AM
Last Post: Gribouillis
  bytearray object - why converting to ascii? Chepilo 2 4,660 Nov-21-2022, 07:25 PM
Last Post: Chepilo
  Bytearray substitution Vismuto 1 3,447 Apr-14-2020, 09:18 AM
Last Post: TomToad
  int() function with bytearray() Jona66 1 2,972 Sep-08-2019, 12:41 PM
Last Post: ichabod801
  Conversion needed from bytearray to Floating point braveYug 1 4,749 May-07-2018, 12:23 PM
Last Post: snippsat
  Windows DIB format in bytearray to image? dusca 2 3,550 Mar-28-2018, 10:35 PM
Last Post: dusca

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020