Positions can be implemented using the OR operator "|:
Y = x | (1 <n );
Purge can be implemented with the operator:
Y = x &(~ (1 <n ));
The inversion can be implemented using the XOR operator "^:
Y = x ^ (1 <n );
Bit extraction operation:
Bit = (X | (1 <n)> N;
In general, bitwise operations are bitwise operations. Bit operations include
^ Exclusive or
| Bit or
& Bit and
~ Bitwise Inversion
> Right shift
<Left shift
The advantage of the bitwise operation is that the computation time and speed can be calculated directly based on the computation speed, which is basically the same as that of the Assembly.
Many bitwise operations are used directly to Express hardware computing or increase the computing speed.
For example, if the number is 16, the bitwise operation shifts four places to the left.
The other is bitfield.
It defines a special struct with only a specified number of members.
For example
Struct instruction {
Unsigned short SR: 5;
Unsigned short TR: 5;
Unsigned short OP: 6;
};
Defines the structure of a 16-bit command.
SR: TR: op
1-5: 6-10: 11-16
Then you can perform this operation.
Struct instruction mov_r1_r3 = {0x01, 0x03, 0x01 };
Then mov_r1_r3 is actually equal to 0x0461
This code is generally compiled to make it easy to use hardware interfaces and complete underlying operations.
The actual Code rarely appears, usually in interfaces with hardware.