Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
parsing question
#7
Something like this then:

import struct

b = b'\x00\xd0\xffp\x01p\x01 \x00 \xff\xa0\x00 \x01\x90\x00\xf0\x00\xf0\x00 \x01P'
size, mod = divmod(len(b), 2)
if mod:
    print("Odd number of bytes seen.  Ignoring final byte")
    b = b[:-1]
uint16_data = struct.unpack(f'>{size}H', b)
for uint in uint16_data:
    print(f"{uint:04x}")
You can change the > to < to reverse the endian order.

00d0
ff70
0170
0120
0020
ffa0
0020
0190
00f0
00f0
0020
0150
Reply


Messages In This Thread
parsing question - by ridgerunnersjw - Oct-09-2020, 07:50 PM
RE: parsing question - by bowlofred - Oct-09-2020, 08:20 PM
RE: parsing question - by ridgerunnersjw - Oct-09-2020, 08:38 PM
RE: parsing question - by bowlofred - Oct-09-2020, 09:13 PM
RE: parsing question - by Skaperen - Oct-10-2020, 02:48 AM
RE: parsing question - by ridgerunnersjw - Oct-10-2020, 06:55 PM
RE: parsing question - by bowlofred - Oct-10-2020, 08:10 PM
RE: parsing question - by ridgerunnersjw - Oct-10-2020, 09:04 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  parsing question ridgerunnersjw 3 2,096 Oct-06-2020, 02:06 AM
Last Post: micseydel
  string parsing question ( I think) diggee17 4 3,121 Jul-24-2019, 02:37 PM
Last Post: diggee17
  Parsing Large Numbers Question amyvaulhausen 5 3,463 Mar-24-2019, 08:46 AM
Last Post: samsonite

Forum Jump:

User Panel Messages

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