How does C++ represent the power (the caret ^ does not mean the power, nor does e mean the power)

1. The caret (^) does not mean a power, but an XOR operator

First of all, note that the caret (^) in C++ does not mean a power, it means an XOR operator!
XOR operator, perform "XOR" operation by binary bit . Operation rules:
same as 0, different as 1

0^0=0;   
0^1=1;   
1^0=1;  
1^1=0;

Suppose if A = 60, and B = 13, now represented in binary format, they look like this:

A = 0011 1100

B = 0000 1101
A^B = 0011 0001
which is 49.

2. Use pow to represent the power

The most practical way is to use the pow function in <math.h>, remember to include <math.h>

pow(base, exponent);

Where base is the base and exponent is the index
such as: pow(2, 3) = 8

3. Scientific notation

C++ uses e to represent scientific notation, and don't confuse it with power notation.
For example: 0.01 = 1e-2
100 = 1e2

Guess you like

Origin blog.csdn.net/Sansipi/article/details/127596944