Working with Bits and Bit Fields in C and Objective-C

We’ll cover two bit related topics in this post: getting/setting bits directly within an integer and working with bit fields in a C structure. Both have their place, it’s more about the context in which you need to use them.

The first example will be getting/setting of specific bits using an integer value along with a pre-defined set of bits we want to access. From there we will look at creating a structure that has named bit fields, making access (and code readability) much easier.

Continue reading