Efficient handling of fast, real-time hex data

Michael Torrie torriem at gmail.com
Tue May 31 20:35:44 EDT 2016


On 05/31/2016 06:20 PM, jladasky at itu.edu wrote:
> So, how can I take the byte sequence <0x01 0x02 0x03 0x04 0x05 0x06
> \n> that Serial.readline() returns to me, and QUICKLY turn it into
> three integer values, 258, 772, and 1286?  Better yet, can I write
> these bytes directly into an array (numpy is an option), since I'm
> going to have a lot of them?

I think you might want to use the struct module. It's designed for this
kind of packing and unpacking:

https://docs.python.org/3/library/struct.html

> I never thought I would find a task that's easier for me to imagine
> doing in C than in Python, but at the moment this is one.  Thanks for
> any suggestions!

Byte and bit twiddling are things that C has always been fast at.  But I
think Python probably could do it.





More information about the Python-list mailing list