1. & and bitwise operators.

Source: Internet
Author: User

This is a separate piece, because it is unclear (although the content is not enough), and I have not made it clear before, so it is necessary to write it out.

The bitwise operators also start from the difference between & (| and | similar. In fact, for the logic and (and) operations of the two boolean values, the results are exactly the same as those of &, but the performance of & is better, because & has the short circuit function. That is, A & B calculates the values of two A and B and returns this result, the result of A & B is false if A is false. For example, when there is a user object,

1 if(user != null && String.IsNullOrEmpty(user.Name))2 {3   ;          4 }

 

In the preceding example, if is not allowed when user = NULL

if(user != null & String.IsNullOrEmpty(user.Name)){  ;          }

The nullreferenceexception is thrown, and the object is not referenced to the instance.

After talking about the difference between "&" as a boolean operator and "&", then "&" as a bitwise operator. Bitwise operators process a series of bits stored in variables. Including &, | ,~ , >>And <<are bitwise AND, bitwise OR, bitwise inversion, right shift, and left shift. The meaning is already clear. In addition, because the numeric types are fixed-length values, the carry is gone and the removed bits are gone.

In more words, due to the underlying structure restrictions, combined with the original code, back code, and complement code, there will be ~ 1 =-2 results. Because the original code of 1 is 00000000000000000000000000000001 ,~ 1. The result of bitwise inversion is 11111111111111111111111111111110, int is signed, and negative is the complement code. The original codes, anticodes, and supplementary codes of positive numbers are the same. The first digit of a negative number is the symbol bit, the second digit is the absolute value, the second digit is the symbol bit, and the second digit is the inverse digit, the complement is equal to the anti-code plus 1. The source code of-2 is 10000000000000000000000000000010, the reverse code is 11111111111111111111111111111101, And the complement code is 11111111111111111111111111111110. For int-type literal values 1 and-2, we have ~ 1 =-2 is true.

In general, there are still some clear things.

1. & and bitwise operators.

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.