| Start |
|---|
| - bitwise OR Output
Why A bit wise When the binary value for The bit wise OR does not change the value of the original values unless specifically assigned to using the bit wise assignment compound operator |
^ - bitwise XOR (exclusive OR) Output
Why A bit wise Notice that with an XOR operation Using this, when the binary value for The bit wise XOR does not change the value of the original values unless specifically assigned to using the bit wise assignment compound operator The bit wise XOR can be utilized in many ways and is often utilized in bit mask operations for encryption and compression. Note: The following example is often shown as an example of a nice trick. But should not be used in production code (there are better ways You can also utilize an XOR operation to swap two variables without a temporary: To productionalize this you need to add a check to make sure it can be used. So though it looks like a nice trick in isolation it is not useful in real code. xor is not a base logical operation,but a combination of others: a^c=~(a&c)&(a|c) also in 2015+ compilers variables may be assigned as binary: |
& - bitwise AND Output
Why A bit wise When the binary value for The bit wise AND does not change the value of the original values unless specifically assigned to using the bit wise assignment compound operator |
<< - left shift Output
Why The left bit wise shift will shift the bits of the left hand value ( But it should be noted that the left shift operation will shift all bits to the left, including the sign bit, example: Possible output: While some compilers will yield results that seem expected, it should be noted that if you left shift a signed number so that the sign bit is affected, the result is undefined. It is also undefined if the number of bits you wish to shift by is a negative number or is larger than the number of bits the type on the left can hold, example: The bit wise left shift does not change the value of the original values unless specifically assigned to using the bit wise assignment compound operator |
>> - right shift Output
Why The right bit wise shift will shift the bits of the left hand value ( It is also undefined if the number of bits you wish to shift by is a negative number, example: The bit wise right shift does not change the value of the original values unless specifically assigned to using the bit wise assignment compound operator |
~ - bitwise NOT (unary complement) Output
Why A bit wise The bit wise NOT can also be a convenient way to check the maximum value for a specific integral type: The bit wise NOT does not change the value of the original value and does not have a compound assignment operator, so you can not do The bit wise NOT ( RemarksBit shift operations are not portable across all processor architectures, different processors can have different bit-widths. In other words, if you wrote This value would be different on a 64 bit machine vs. on a 32 bit machine, or from an x86 based processor to a PIC based processor. Endian-ness does not need to be taken into account for the bit wise operations themselves, that is, the right shift ( |
Read Article
https://develop.horje.com/learn/1434/reference