Home >Web Front-end >JS Tutorial >js basics improvement learning operators and expressions
This time I will bring you operators and expressions to improve the basics of js. What are the precautions for using js operators and expressions? The following is a practical case, let's take a look.
How can we get the binary representation of a number?
Format: alert(variable name.toString(2));
If you want to get the other base of a number, you only need to change the base name in toString (base name) That's it.
First of all, the number must be converted into binary. The algorithm is that only if both are one at the same time, then the result will be 1, and the other results will be 0
XOR: When the two values are the same, 0, not 1 at the same time. The symbol is: ^
The role of XOR operation:
x^1=*(反) x^0=x
The bitwise AND operation can be used to test whether a certain bit is 0 or 1;
1100010000101011 0000000000000111
Set a certain bit to 0
1100010000101011 1111111111110111
The role of bitwise OR operation: set some bits to 1
1100010000101011 0000000000010000
I believe you have mastered the method after reading the case in this article, please pay attention for more exciting things Other related articles on php Chinese website!
Recommended reading:
Basic data types for js basic improvement learning
Summary and Q&A of JS concept questions
The above is the detailed content of js basics improvement learning operators and expressions. For more information, please follow other related articles on the PHP Chinese website!