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
  appending to a bytearray Skaperen 21 14,728 Mar-19-2023, 11:05 PM
Last Post: Skaperen
  Split Bytearray into separate Files by Hex delimter lastyle 5 2,728 Mar-09-2023, 07:49 AM
Last Post: bowlofred
  Save multiple Parts of Bytearray to File ? lastyle 1 972 Dec-10-2022, 08:09 AM
Last Post: Gribouillis
  bytearray object - why converting to ascii? Chepilo 2 1,677 Nov-21-2022, 07:25 PM
Last Post: Chepilo
  Bytearray substitution Vismuto 1 2,636 Apr-14-2020, 09:18 AM
Last Post: TomToad
  int() function with bytearray() Jona66 1 2,417 Sep-08-2019, 12:41 PM
Last Post: ichabod801
  Conversion needed from bytearray to Floating point braveYug 1 4,145 May-07-2018, 12:23 PM
Last Post: snippsat
  Windows DIB format in bytearray to image? dusca 2 2,793 Mar-28-2018, 10:35 PM
Last Post: dusca
  Bytearray questions mattps 2 14,424 Mar-25-2018, 06:54 AM
Last Post: mattps
  ByteArray outside while true Schampbakken 5 4,406 Feb-18-2018, 02:02 PM
Last Post: buran

Forum Jump:

User Panel Messages

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