I have an integer coming out of a hardware device that has several values embedded in it as arbitrary length bit fields.
For example, I have a "status" value that is a 16 bit integer with several values inside of it. One is a 4 bit integer beginning on the third bit.
I'm extracting it using a function I wrote:
def vnGetFieldFromStatus(status):
return ((status & 0b0001111000000000)>> 9)
This, I believe, is working fine.
Is there a generalized pythonic way to grab an int composed of i bytes starting at byte j?