Bitwise operations and bitwise operations in enums

Source: Internet
Author: User
Tags arithmetic bitwise

1. bitwise logical Non-arithmetic ~A bitwise logical non-operation is single-purpose, with only one operand. Bitwise logical non-operation bitwise pairs the value of an operand into a non-operation, i.e. if one is equal to 0, it is converted to 1, and if one is equal to 1, it is converted to 0. For example, the binary 10010001 is a bitwise logical non-operation, the result is equal to 01101110, in decimal notation is: ~145 equals 110, the binary 01010101 is a bitwise logical non-operation, the result is equal to 10101010. In decimal notation is ~85 equals 176. 2 , bit logic and operations &Bitwise logic and operations perform bitwise AND operations on two operands. Rules with operations: 1 and 1 equals 1, 1 and 0 equals 0, 0 and 0 equals 0. Only 1&1 = 1 and the rest are 0 for example: 10010001 (binary) &11110000 equals 10010000 (binary). 3. bit logic or operations |Bitwise logic OR operation bitwise OR operation of two operands. Or the rule of operation is: 1 or 1, etc. 1, 1 or 0 equals 1, 0 or 0 equals 0. Only 0|0=0, the rest are 1 such as 10010001 (binary) | 11110000 (binary) equals 11110001 (binary). 4 , bitwise logical XOR, or operation ^A bitwise logical XOR operation makes two operands bitwise XOR. The rules for XOR operations are: 1 xor or 1 equals 0, 1 xor or 0 equals 1, 0 xor or 0 equals 0. That is, the same 0, different 1. For example: 10010001 (binary) ^11110000 (binary) equals 01100001 (binary). 5 , bitwise left shift arithmetic <<The bitwise left shift operation shifts the entire number of digits to the left by a number of bits, left-shifted to the vacated portion 0. For example: A 8-bit byte variable byte a=0x65 (that is, binary 01100101), moving it 3 bits to the left: the result of A<<3 is 0x27 (that is, the binary 00101000). 6 , bitwise right SHIFT arithmetic >>The bitwise right SHIFT operation shifts the entire number of digits to the right by several bits, and the vacated portion of the right shift is 0. For example: A 8-bit byte variable byte a=0x65 (both (binary 01100101)) shifts it to the right 3 bits: The result of A>>3 is 0x0c (binary 00001100).
[Flags] Public enumClassstatisticstype {applyaudition=1<<0,//which is 2 of the power of 0.Required=1<<1,//which is 2 of the power of 1.Participation=1<<2,//which is 2 of the power of 2.Normal=1<<3,//which is 2 of the power of 3. All= Applyaudition | Required | Participation | Normal//that is, 2 of the power of 0 + 2 of 1 Power + 2 2 Power + 2 power of 3 times}

            var c1 = classstatisticstype.all;             var c2 = classstatisticstype.normal;             var c3 = C1 & C2; // used to determine if C1 contains c2,>0, <=0 does not contain            var c4 = c1 ^ C2; // Remove C2 from C1             Console.WriteLine (C1);            Console.WriteLine (C2);            Console.WriteLine (C3);            Console.WriteLine (C4);

Bitwise operations and bitwise operations in enums

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.