Time to dust off that C book!
Ok. That’s the C code I wrote in my head as I was typing the last post but didn’t dare put down because my C skills are definitely dusty! The missing link has been solved.
Note that in many (most?) cases you’ll be dealing with individual bits, not whole bytes, so there’s a lot of ANDing and ORing that happens.
Then you get to the Cerberus and you get bit-banding. Fun stuff!