[Tutor] [spoiler] Re: Shifting arrays as though they are a 'word'
alan.gauld at yahoo.co.uk
Tue Oct 9 12:18:32 EDT 2018
On 09/10/18 14:21, Chip Wachob wrote:
> The API is providing me with a bytearray-formatted result, but the API
> only reads one whole byte, or eight bits, at a time.
Being slightly picky but an octet and a byte are subtly different.
An octet is a group of 8 bits with no meaning attached.
So an octet contains 8 bits which could be individual
single bit flags, or they could be two groups of 4(nibbles)
or a single group of 8(a byte). A byte is a more specific
thing that only exists as a set of 8 bits joined together
as a single unit of data.
Most of the time it makes no significant difference so
people often use the terms interchangeably but in this
kind of scenario the difference is significant.
You are reading octets and want to convert them into
a bytearray - removing the extraneous bits in the process.
The way I'd do that is convert to an int and then do
a single shift right on the result.
Author of the Learn to Program web site
Follow my photo-blog on Flickr at:
More information about the Tutor