If you're reading this page you are not happy with just getting the code to work, you want to understand what is going on. There are many different ideas of how to describe what binary bit manipulation means, this is ours. Hope this helps.
Binary is the representation of a number in base-2 (0,1). Typically numbers are represented in base-10 (0,1,2,...,9) and need to be converted from base-10 to base-2 for use with computers. The use of base-2 values with companion quality control fields is to use the number as a binary statement of true/false. Therefore, it is best to not think of the number of powers of 2. That will just lead to confusion.
The code examples use bit-shifting routines to allow the use of test numbers instead of forcing the user to create the binary representation. The creation of a binary number for small number of tests is reasonable, although some may consider the creation of a binary number representing more than 12 tests difficult. The intent of this menthod is to retain the notion of test numbers.
This is a very condensed amount of code so let's take it step by step. First, we list the tests we want to set, [1, 2, 3, 5]. We can think of tests and bits interchangeably. To help, here are the first 16 base-10 numbers and the equivalent number in base-2.
The code is using the left shift function to take a number and shift the bit set a number of positions to the left. To make things simple the number we are shifting is alway the number 1 (000 001). So to make 2 we shift 1 by one bit. To make the number 4 we shift 1 by two bits. Because we only care about numbers where one bit is set, we will only create numbers like 1, 2, 4, 8, 16, ... Although, to get the shifting correct we need to start at 0 and move bits to the left. Because the function will only shift a number greater than 0 we need to start with 1 (000 001). This means to create the binary representation from a number that already has the first bit tripped we need to subtract 1 from the bit postion we want to set, effectivly shifting 1 less. That is why the code uses tests-1.
We are also taking advantage of the language's native vector processing so multiple numbers are created when tests is a vector of more than one value.