Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Michael Torrie Newsgroups: comp.lang.python Subject: Re: Efficient handling of fast, real-time hex data Date: Tue, 31 May 2016 18:35:44 -0600 Lines: 20 Message-ID: References: <24081cb5-c5e2-44e4-948f-ecf01ebaf7e6@googlegroups.com> <816aa3d4-352d-0289-f9b5-00cd8798c9ae@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de zi+GODfA3gtkMNbztPovVAM2hH3cYZckJuhUYC3/1rng== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.017 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'python,': 0.02; 'python': 0.10; 'at.': 0.16; 'from:addr:torriem': 0.16; 'from:name:michael torrie': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subject:handling': 0.16; 'wrote:': 0.16; 'byte': 0.18; 'bytes': 0.18; 'integer': 0.18; 'struct': 0.22; 'bit': 0.23; 'header:In- Reply-To:1': 0.24; 'header:User-Agent:1': 0.26; 'module.': 0.27; 'sequence': 0.27; 'them?': 0.29; 'array': 0.29; "i'm": 0.30; 'task': 0.30; 'probably': 0.31; 'url:python': 0.33; 'message- id:@gmail.com': 0.34; 'quickly': 0.34; 'so,': 0.35; 'could': 0.35; 'subject:time': 0.35; 'but': 0.36; 'url:org': 0.36; 'url:library': 0.36; 'to:addr:python-list': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'turn': 0.37; 'thanks': 0.37; 'received:org': 0.37; 'thought': 0.37; 'things': 0.38; 'doing': 0.38; 'received:192': 0.39; 'subject:-': 0.39; 'to:addr:python.org': 0.40; 'url:3': 0.60; 'charset:windows-1252': 0.62; 'packing': 0.84; 'imagine': 0.96 X-Virus-Scanned: amavisd-new at torriefamily.org User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.0 In-Reply-To: <24081cb5-c5e2-44e4-948f-ecf01ebaf7e6@googlegroups.com> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: <816aa3d4-352d-0289-f9b5-00cd8798c9ae@gmail.com> X-Mailman-Original-References: <24081cb5-c5e2-44e4-948f-ecf01ebaf7e6@googlegroups.com> Xref: csiph.com comp.lang.python:109294 On 05/31/2016 06:20 PM, jladasky@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.