What are bit operators?

In the computer program, the operators of the bit newspaper are operators for handling bits in terms. Bitwise A, or exclusive or (xor), no, the right shift and the left shift are common operations. Most computer programming languages ​​include all six of these operators. They are often used for setting up, cleaning or rolling individual bits in programs that control computer hardware. Biřas operators are also often used in data encryption and data compression algorithms. They are used in expressions as well as arithmetic operators such as plus or minus brands. Bitwise operator A is represented by Ampersand & , or with a tube | | and xor with Caret ^. No, also known as the supplements operator, is marked with the influence of ~ .

The right Shift operator uses a double envelope pointing to the right > . On the other hand, the shift is marked with a double feeling of left point <<. Java includes another right shift operation displayed with the right Tripping B routingoje >>> .

Bitwise operators apply a logical operation to every few bits in their operands. No, the right shift and the shift on the left have only one right operand; The second value in Shift operations is the number of bits. In order to better understand how bit work operators work, the individual can visualize his operands as binary digits. For example, the accessories operator will overturn every piece of its one -off operand to the opposite state. One becomes zero and zero becomes. 8 -bit binary value 001101 is 11001010.

and the operator has two operands. The bit of a piece is logical and the operation is performed using one corresponding bits from each operand. The result of each bit operation is placed in this bit position the overall result. For example, the Andes operator will process Bit 7 from one operand with a bit of 7 other operand. The result will be stored in Bit 7 of the total result.

In the operation and operation, both operand must be bits to make the result one, otherwise the result is zero. For example, if the 8 -bit binary values ​​are 00110101 and 11110000, the result will be 00110000. The common use of the Andes operator is zero some bits in the result. This is done by placing zeros in these bit positions in one of the operands.

in OR surgery, both operand must be zero to make the result zero; Otherwise, the result is one. The common use of the OR operator is to set certain bits of the result to those. This is done by placing in these bit positions in one of the operands. For XOR surgery, the result is zero if both operand bits are zero or if both operand bits are one - the result is one.

Left shift and right shift move the bits in the operand left or right according to the specified number of bit positions. The logical right shift will move zero to the left of the most confident bits in the shift. Arithmetic right shift copy the bit to the left - the emblem piece - before moving to the STejné positions after the shift. The original bit is also moved directly with the rest. One type of left shift moves zero to the right bit.

6 Similarly, on the left most before the liquidation on the left. It does not shine at the other end of the operand.

Bitwise Shift Operations are language and implementation dependent. For example, in C and C ++, >> and <<< do logical shifts if the operand is an unsigned integer. If the operand is signed by the full number, it is likely that the arithmetic shift will be performed instead. In Java, all operands are considered signed and arithmetic shifts are always done with >> and <<. The operator >> is used for a logical right shift, but it is still possible to randomly make an arithmetic right shift without a careful type.

Complications may also occur when operands have different bit lengths or when some are signed and some are unsigned. Bitwise operators and numerical constants in the middle of a complex eagleZU does not have to be evaluated as expected. It is necessary to pay attention to the size and signed/unsigned nature of each amount in the expression. This can be done with a careful type or interim assignments to specific types of variables in the program code.

IN OTHER LANGUAGES

Was this article helpful? Thanks for the feedback Thanks for the feedback

How can we help? How can we help?