In this section, you will learn the assembly instructions that operate on the bits. The bits are numbered starting from the far right; the rightmost bit (least significant bit) has a bit position of 0, and the bit position increases toward the left. The left-most bit is called the most significant bit. The following is an example showing the bits and the bit positions for a byte, 5D (0101 1101). The same logic applies to a word, dword, and qword:

One of the bitwise instructions is the not instruction; it takes only one operand (which serves as both the source and destination) and inverts all of the bits. If eax contained FF FF 00 00 (11111111 11111111 00000000 00000000), then the following instruction would invert all of the bits and store it in the eax register. As a result, the eax would contain 00 00 FF FF (00000000 00000000 11111111 11111111):
not eax
The and, or, and xor instructions perform bitwise and, or, and xor operations and store the results in the destination. These operations are similar to and (&), or (|), and xor (^) operations in the C or Python programming languages. In the following example, the and operation is performed on bit 0 of the bl register and the bit 0 of cl, bit 1 of bl and the bit 1 of cl, and so on. The result is stored in the bl register:
and bl,cl ; same as bl = bl & cl
In the preceding example, if bl contained 5 (0000 0101) and cl contained 6 (0000 0110), then the result of the and operation would be 4 (0000 0100), as shown here:
bl: 0000 0101
cl: 0000 0110
--------------------------------------
After and operation bl: 0000 0100
Similarly, or and xor operations are performed on the corresponding bits of the operands. The following shows some of the example instructions:
or eax,ebx ; same as eax = eax | ebx
xor eax,eax ; same eax = eax^eax, this operation clears the eax register
The shr (shift right) and shl (shift left) instructions take two operands (the destination and the count). The destination can be either a register or a memory reference. The general form is shown as follows. Both of the instructions shift the bits in the destination to the right or left by the number of bits specified by the count operand; these instructions perform the same operations as shift left (<<) and shift right(>>) in the C or Python programming languages:
shl dst,count
In the following example, the first instruction (xor eax, eax) clears the eax register, after which 4 is moved into the al register, and the content of the al register (which is 4 (0000 0100)) is shifted left by 2 bits. As a result of this operation (the two left-most bits are removed, and the two 0 bits are appended to the right), after the operation the al register will contain 0001 0000 (which is 0x10):
xor eax,eax
mov al,4
shl al, 2
The rol (rotate left) and ror (rotate right) instructions are similar to shift instructions. Instead of removing the shifted bits, as with the shift operation, they are rotated to the other end. Some of the example instructions are shown here:
rol al,2
In the preceding example, if al contained 0x44 (0100 0100), then the result of the rol operation would be 0x11 (0001 0001).