15.4.14 Bit operation
15.4.14.1 BitAnd
Explanation |
BitAnd is used to generate logical conjunction (and) for byte type data. See table below:
|
Definition |
Return value, data type: byte, the result returned by performing logical conjunction of two byte-type data. BitAnd (BitData1, BitData2); BitData1, data type: byte, the byte data 1 to be processed. BitData2, data type: byte, the byte data 2 to be processed. |
Example |
Example 1
Define the byte-type variable data1 and data2. assign them with the value of 34 and 38, respectively; perform logical conjunction on data1 and data2, the returned value of 34 is assigned to byte3. |
15.4.14.2 BitCheck
Explanation |
It is used to check whether a bit in a byte-type data is 1. If so, returns true, otherwise, false. |
Definition |
Return value, data type: bool, true indicates the bit is assigned to 1, false indicates the bit is assigned to 0. BitCheck (BitData, BitPos); BitData, data type: byte, the byte data to be processed. BitPos, data type: int, the position of byte to be operated, ranging from 1 to 8. |
Example |
Example 1
Definite byte data1 and assign it with 130, check if the 8th bit of data1 is 1 and return true if so. |
15.4.14.3 BitClear
Explanation |
To set a certain bit of byte- or int-type data to 0. The bit starts from 1. |
Definition |
BitClear(BitData | IntData, BitPos); BitData, data type: byte, the byte data to be processed. IntData, data type: byte, the byte data to be processed. BitPos, data type: int, the position of the bit to be operated, ranging from 1 to 8 for byte data and 1 to 32 for int data. |
Example |
Example 1
Define byte-type variable data1 and assign it with 255, Perform BitClear on data1, set the first bit to 0, and 254 is returned, set the second bit to 0, and 252 is returned. |
15.4.14.4 BitLSh
Explanation |
It is used to perform logical left shift on byte-type data. |
Definition |
Return value, data type: byte, the byte data obtained by performing the left-shift operation. BitLSh (BitData, ShiftSteps); BitData, data type: byte, the byte data to be processed. ShiftSteps, data type: int, the bits selected for the left shift, ranging from 1 to 8. |
Example |
Example 1
Define byte-type variable data1, and assign it with 38, perform 3 bits left shift on data1, and 48 is returned. |
15.4.14.5 BitNeg
Explanation |
It is used to perform logical negation on byte-type data. |
Definition |
Return value, data type: byte, the byte data obtained by performing the logical negation. BitNeg (BitData); BitData, data type: byte, the byte data to be processed. |
Example |
Example 1
Define byte-type variable data1, and assign it with 38, perform logical negation on data1, and 217 is returned. |
15.4.14.6 BitOr
Explanation |
It is used to perform logical disjunction (or) on byte-type data. |
Definition |
Return value, data type: byte, the byte data obtained by performing the logical disjunction. BitOr (BitData1, BitData2); BitData1, data type: byte, the byte data 1 to be processed. BitData2, data type: byte, the byte data 2 to be processed. |
Example |
Example 1
Define the byte-type variable data1 and data2, assign them with the value of 39 and 162, respectively; perform logical conjunction on data1 and data2, and 167 is returned. |
15.4.14.7 BitRSh
Explanation |
It is used to perform the logical right shift on byte-type data. |
Definition |
Return value, data type: byte, the byte data obtained by performing the right-shift operation. BitLSh (BitData, ShiftSteps); BitData, data type: byte, the byte data to be processed. ShiftSteps, data type: int, the bits selected for the right shift, ranging from 1 to 8. |
Example |
Example 1
Define byte-type variable data1, and assign it with 38, perform 3 bits right shift on data1, and 4 is returned. |
15.4.14.8 BitSet
Explanation |
It is used to set a certain bit of byte- or int-type data to 1. The bit starts from 1. |
Definition |
BitSet (BitData | IntData, BitPos); BitData, data type: byte, the byte data to be processed. IntData, data type: byte, the byte data to be processed. BitPos, data type: int, the position of the bit to be operated, ranging from 1 to 8 for byte data and 1 to 32 for int data. |
Example |
Example 1
Define byte-type variable data1 and assign it with 255, Perform BitSet on data1, set the first bit to 1, and 1 is returned, set the second bit to 1, and 3 is returned. |
15.4.14.9 BitXOr
Explanation |
It is used to perform logical exclusive or on byte-type data. |
Definition |
Return value, data type: byte, the byte data obtained by performing the logical disjunction. BitXOr (BitData1, BitData2); BitData1, data type: byte, the byte data 1 to be processed. BitData2, data type: byte, the byte data 2 to be processed. |
Example |
Example 1
Define the byte-type variable data1 and data2, assign them with the value of 39 and 162, respectively; perform logical exclusive or on data1 and data2, and 133 is returned |
