c sharp bit operator collation

  • 2020-05-05 11:47:26
  • OfStack

The bitwise logical operators supported by C# are shown in table 2.9. Operation symbolic meaning operation object type result type object number instance ~ Bit logic non operation integer, character integer 1 ~a & Bit logic and operations 2 a & b | Bit logic or operations 2 a | b ^ Bit logic xor operation 2 a ^ b < <   The bit moves left to 2 a < < 4 > >   Bit right shift operation 2 a > > 2   1, bit logical non-operations bit logical non-operations are single-purpose, with only one operation object. Bitwise logic nonoperation on the value of the operational object, that is, if a bit is equal to 0, it is converted to 1; If a digit is equal to 1, it is converted to 0. For example, if the binary 10010001 is not operated in bit logic, the result is equal to 01101110, which is expressed as: ~145 is equal to 110; The result of bit logic nonoperation on binary 01010101 is equal to 10101010. So in decimal notation, this is minus 85 is equal to 176.   2 bit logic and operations bit logic and operations. The rule of sum operations: 1 and 1 equals 1, 1 and 0 equals 0. For example: 10010001 (binary) &11110000 is equal to 10010000 (binary).   The bitwise logical or operation of two operations. The rule of the or operation is: 1 or 1 equals 1, 1 or 0 equals 1, 0 or 0 equals 0. Let's say 10010001 (binary) | 11110000 (binary) is equal to 11110001 (binary).   The bitwise logical xor operation performs an xor operation on two operands. The rule of the xor operation is: 1 xor 1 equals 0, 1 xor 0 equals 1, 0 xor 0 equals 0. That is, the same gets 0, different gets 1. For example: 10010001 (binary) to the 11110000 (binary) is equal to 01100001 (binary).   The left shift operation moves the whole number a certain number of bits to the left, leaving the empty part 0. For example, the 8-bit byte type variable byte a=0x65(i.e., binary 01100101), move it 3 bits to the left: a< < The result of 3 is 0x27(i.e., 00101000 in binary).   The bit-shift operation moves the whole number to the right by a number of bits, and then fills in 0 for the empty part. For example, the 8-bit byte type variable Byte a=0x65(both (binary 01100101)) moves it to the right by 3 bits: a> > The result of 3 is 0x0c(binary 00001100).   In the case of bit-and-, or, or xor operation, if the types of two operands are the same, the type of the result of the operation is the type of the operand. For example, if two int variables a and b are combined, the type of operation result is int. If two operands are of different types, C# casts the inconsistent type into a consistent type, and then performs the operation. The rules for type conversions are the same as for integer conversions in arithmetic operations.   is a bit operand concatenating integer expression.

Related articles: