Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What types of operators can be classified in C++ and what is their usage?

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

The purpose of this article is to share with you about the categories and uses of operators in C++. The editor thinks it is very practical, so I hope you can learn something after reading this article. Let's take a look at it with the editor.

The previous part

In the previous article, we talked about arithmetic operators, shift operators, and we also told you several knowledge points again by the way. I believe that with the basis of the previous article, this class will be particularly easy.

The positive film begins.

In this article, let me explain to you what the bit operator is and what the assignment operator is.

First of all, let's start with the concept, what is a bit operator? Which bit is the operator again? The operation here is the binary bit. The bit operator is to execute the binary numbers in accordance with the prescribed program.

The symbols here are:

The meaning of symbols & bitwise and | bitwise or ^ bitwise XOR

Bitwise vs.:

So let's start with bit-by-bit and, let's give an example:

Like this, because the binary bit of 3 here is: 011.

5 the binary bit here is 101

Here, we call 0 false and 1 true.

When it comes to bit by bit, one false is false, and the whole truth is true. So, it means:

Here we calculate that the result is 001, we are converting this binary number to a decimal number and the result is 1, which can be debugged in the program now. Let's take a look at the debugging results.

The answer is yes.

Bitwise or:

First give a chestnut, we often say, An or B can help, then this sentence means that A comes, B does not have to come, B does not have to come, A does not have to come. Bitwise or the same reason, writing and bitwise and consistent just replace & with, we can analyze the working principle of bitwise or according to bitwise sum. be the same in essentials while differing in minor points.

It also has a formula: if it is true, it is true, and if it is false, it is false. Let's still give you a vivid example of 3Jing 5:

Here the binary number is 111 and the converted decimal number is: 7

Let's pass the code and take a look at the answer.

As a result, it is found that the above is correct.

Bitwise XOR:

Next, let's talk about the last point of knowledge: different or by position.

Some rookies will say in their hearts that we can imitate the concepts of the previous two forms, and we can guess what is different by position or something.

The answer is yes.

Bit-by-bit and is: one false is all false, all true is true.

Bitwise or: true is true, all false is false.

Then, some rookies will think whether it will be: all true or false, all false is true? This conjecture is half wrong.

Bitwise XOR is calculated as follows: if the corresponding binary bit is the same, it is false, and the corresponding binary bit difference is true. So what does this mean? Let's take a look.

We can see that the result of the output is: 110 converts the decimal number to 6

Let's take a look at the actual answer:

The answer is exactly the same!

Let me give you some tips for this article, so that you will get twice the result with half the effort when you study.

Bit by bit and: one false is all false, all true is true.

Bitwise OR: true is true, all false is false.

Bitwise XOR: the difference is true and the same is false.

These are the categories and uses of operators in C++. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report