Numeric type conversions



I'm new to Python and can't readily find the appropriate function for
the following situation:

I'm reading in a byte stream from a serial port (which I've got
working OK with pyserial) and which contains numeric data in a packed
binary format. Much of the data content occurs as integers encoded as
2 consecutive bytes, ie a 2-byte integer.

I'm guess that there should be a function available whereby I can say
something like:

My2ByteInt = ConvertToInt(ByteStream[12:13])

to take a random example of the 2 bytes occurring at positions 12 and
13 in the byte stream.

Can anyone point me in the right direction towards a suitable function
please?

NB I don't know without further checking exactly how the bytes are
encoded, but I'm just transcribing some code across from a Windows
VB.Net program and these same bytes could be read straight into a
standard 2-byte signed short int, so I can be confident that it's a
fairly standard Windows-compatible encoding.
.



Relevant Pages

  • Re: Numeric type conversions
    ... I'm reading in a byte stream from a serial port (which I've got ... working OK with pyserial) and which contains numeric data in a packed ...
    (comp.lang.python)
  • Re: Numeric type conversions
    ... I'm reading in a byte stream from a serial port (which I've got ... working OK with pyserial) and which contains numeric data in a packed ...
    (comp.lang.python)
  • Re: Numeric type conversions
    ... I'm reading in a byte stream from a serial port (which I've got ... working OK with pyserial) and which contains numeric data in a packed ... Can anyone point me in the right direction towards a suitable function ...
    (comp.lang.python)
  • Re: RS232 Synchronizing of a data glove(lost bytes) and Flock of Birds(lag)
    ... BytesAvailable commands out of the loop and request to read one byte, ... which is always the first byte, 83 (stream echoed back). ... % FOB ... We though it might be a serial port problem since we are using one ...
    (comp.soft-sys.matlab)
  • Re: Numeric type conversions
    ... I'm reading in a byte stream from a serial port (which I've got ... working OK with pyserial) and which contains numeric data in a packed ... but I'm just transcribing some code across from a Windows ... In the format string, '<' means little-endian (almost universal on PCs ...
    (comp.lang.python)