Bottom Page

• 0 Vote(s) - 0 Average
• 1
• 2
• 3
• 4
• 5
 Value error when converting hex value to bytearray shubhamjainj Programmer named Tim Posts: 9 Threads: 6 Joined: Mar 2019 Reputation: 0 Likes received: 0 #1 Mar-01-2019, 06:02 AM Hi, I am getting ValueError: non-hexadecimal number found in fromhex() arg at position 7. Below is the code : Cmd1 = bytearray.fromhex("08 22 1 0 1 0 D4"); Please let me know how to solve this issue ichabod801 Bunny Rabbit Posts: 4,231 Threads: 94 Joined: Sep 2016 Reputation: 272 Likes received: 1264 #2 Mar-01-2019, 06:12 AM It's expecting (hexpecting?) two-digit hex numbers. Craig "Ichabod" O'Brien - xenomind.com I wish you happiness. Recommended Tutorials: BBCode, functions, classes, text adventures shubhamjainj Programmer named Tim Posts: 9 Threads: 6 Joined: Mar 2019 Reputation: 0 Likes received: 0 #3 Mar-01-2019, 06:20 AM Ok Thanks, will check DeaD_EyE Da Bishop Posts: 1,303 Threads: 5 Joined: May 2017 Reputation: 146 Likes received: 289 #4 Mar-01-2019, 08:29 AM ```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. My code examples are always for Python >=3.6.0 Almost dead, but too lazy to die: https://sourceserver.info All humans together. We don't need politicians! « Next Oldest | Next Newest »

Top Page

 Possibly Related Threads... Thread Author Replies Views Last Post Bytearray substitution Vismuto 1 107 Apr-14-2020, 09:18 AM Last Post: TomToad int() function with bytearray() Jona66 1 290 Sep-08-2019, 12:41 PM Last Post: ichabod801 Conversion needed from bytearray to Floating point braveYug 1 799 May-07-2018, 12:23 PM Last Post: snippsat Windows DIB format in bytearray to image? dusca 2 829 Mar-28-2018, 10:35 PM Last Post: dusca Bytearray questions mattps 2 11,938 Mar-25-2018, 06:54 AM Last Post: mattps ByteArray outside while true Schampbakken 5 1,554 Feb-18-2018, 02:02 PM Last Post: buran Error when converting MATLAB's datenum to Python's datetime zoya2385 5 3,937 Apr-03-2017, 06:01 PM Last Post: zivoni readinto a bytearray slice bhowerter 3 3,561 Sep-23-2016, 10:04 PM Last Post: micseydel

Forum Jump:

Users browsing this thread: 1 Guest(s)