Suppose there are several fixed known fields in a word and you wish to frequently determine if any of the fields are zero. We assume here that the fields are contiguous and partition the word.

Pre compute a word with a one bit in the right position of each field. In other words construct a word where each field has value 1. In the code below we call this word ones.

The routine taz returns a word with a field value of 1 whenever the field to its right in the input, was zero.

int taz(uint word, uint ones){return ones&~(word^(word-ones));}
Alas the left most field is not tested here unless you have a ones complement machine. Information about the left field is squirreled away in the condition code and is probably unavailable via the semantics of C. Testing all but the left bit of the left field is sometimes useful but I think it best to give up on including any field that must start in the left bit.

if(taz(data ^ pvs)) ...” tests for particular known values (pvs) in the respective fields.


The HDLC wire protocol requires escaping strings of 8 or more consecutive zero bits. Here is a way to detect any 8 consecutive zeros in a word:
uint h8z(uint word){uint w2 = word | (word>>1), w4 = w2 | (w2>>2);
  return ~(w4|(w4>>4));}
If bits i thru i+7 are all zero then bit i of the answer is 1.