This article mainly describes the JavaScript bitwise LEFT operator (The bitwise Left operator (bitwise Left operator (bitwise Left operator (<<) shifts the bit of "number to be shifted" to the left of the number of digits specified in "offset digits". For example: The code is as follows: Var temp; temp = <
after the operation, and the remaining elements are the ones to be searched. This bitwise operation is "XOR". By XOR, the same number of all bits is 0, and the individual number is itself.When the condition of the topic changes, the number of the array may appear several times, but only one number appears once, looking for this number (assuming that it appears here 3 times).Idea: for integers 32 bits, for each bit, the number of the entire array is c
Bitwise operations are operations that are performed in binary order. In a program, it is often necessary to deal with bits problems. The C + + language provides 6 bit operator operators. These operators can only be used for integer operands, that is, only for signed or unsigned char,short,int and long types.
In practice, it is recommended to use the unsigned integer operand because the signed operand may be different from the results of different mac
Today friends in the group asked the next bitwise and/or questions.
PHP has been working for 1 years, probably not familiar with this one. Introduce this part to the novice friend here.
By being located primarily on the binary number operation.
Copy Code code as follows:
$a = 1;
$b = 2;
$c = $a ^b;
echo $c//3
?>
This is not a simple addition relationship.Decimal 1 translates into binary 00000001
Decimal 2 translates int
complement in C language teaching has a relatively important position, and the interpretation of the complement must involve the original code, the inverse code.
detailed explanationThe original code is the binary fixed-point notation, that is, the highest bit for the symbol bit, "0" is positive, "1" means negative, the remaining bits represent the size of the value.
The anti-code notation stipulates that the inverse code of a positive number is the same as its original code; the inverse of a n
\n", b);printf ("%d\n", c);}
Result is
24
24
14
original code, inverse code and complement
OverviewWithin a computer, there are 3 representations of signed numbers: The original code, the inverse code, and the complement.
In the computer, the data is stored in the form of complement, so the complement in C language teaching has a relatively important position, and the interpretation of the complement must involve the original code, the inverse code.
Detailed explanationThe original code is the
Bitwise computation is the foundation of computer learning. Python fully supports bitwise operators to display the result of bitwise computation almost directly, here we will briefly summarize the Basic decimal bitwise calculation summary and computation examples in Python.
And Operations
Example:3 5Solution: The b
get the value after the displacement.---------------------------------------------------------------------------------Next, here is the advantage of bit operation, the speed is very fast, these are the bottom of the binary machine operation instructions.For example: A*2,1.JVM allocates space for variable a first;2. Perform the a*2 operation again;3. Return the result to the corresponding variable.And aAvailable when the operation is in progress.To add a little bit more, talk about bits and, of
I. Six operators in C language:
Bitwise AND
| By bit or
^ Bitwise OR
~ Invert
> Right shift
1. bitwise AND OPERATION
Bitwise AND operator "" are binary operators.
Its function is the binary phase corresponding to the two numbers involved in the operation. The result bit is 1 only when the two binary numbers are 1. Ot
If you are not clear about bitwise operations, you can read my article, "foundation is the top priority ~ Bitwise calculation and integer variable bitwise calculation (like Enumeration type)
What we want to do today is to verify the difference between bitwise operations (OR) and addition operations (+) and non-operatio
Bitwise non-operators, the simple understanding is to change the number of operands and subtract 1, of course, it is simply a simple understanding of the data can be converted to type numbers.Then, for the type of typeof var!== "number", when the operation is performed, it will attempt to convert to 32-bit shaping data, and if it cannot be converted into the shaping data, it will be converted to Nan;JS is a more convenient way to implement this operat
~: Bitwise non-operator is represented by a wavy line (~), and the result of performing a bitwise non is the inverse code of the return value.
Copy Code code as follows:
var num1 = 3; My lucky number is 3.
var num2 = ~ (NUM1);
Console.log (num2)//"-4"
var num3 =-3;
var num4 = ~ (NUM3);
Console.log (NUM4)//"2"
Console.log (~ (0))//"-1"
Yes, now we know the principle of the
Bitwise left-shift operator (The bit of the left-shift expression.
result = expression1
ParametersResult
Any variable.
Expression1
Any expression.
Expression2
Any expression.
DescriptionThe
var temptemp = The value of the variable temp is 56 because 14 (that is, binary 00001110) shifts to the left two digits equals 56 (that is, binary 00111000).
The Javascript bitwise Left operator (
result = "
The two values that participate in the operation, or 1 if the corresponding digits are the same, the result is 0. namely: 0^0=0, 1^0=1, 0^1=1, 1^1=0
For example: 10100001^00010001=10110000
0^0=0,0^1=1 0 XOR or any number = any number
1^0=1,1^1=0 1 XOR or any number-any number of counter
Any number of differences or own = put yourself 0
(1) bitwise XOR or can be used to flip certain bits, such as the 2nd and 3rd digits of the logarithm 10100001,
#coding =utf-8# "" bitwise AND operation refers to a number converted to binary, then these binary numbers are bitwiseA=718Print a"' first convert 7 to binary, get 7 binary value is 111, auto complement 8 bit, that is 00000111, then 18 into binary, get 18 binary value is 10010, same complement 8 bit, 00010010.We have 00000111 and 00010010 bitwise AND operation, the result is 00000010, and then converted to
Bitwise operatorsBitwise operators are operations that align bits from low to high.
symbols
function
Example
Personal Understanding
Bitwise-AND
$m $n
Full 1 is 1, otherwise 0
|
Bitwise OR
$m | $n
Full 0 is 0, 1 is 1
^
Bitwise operators
Bitwise operators perform bitwise operations between two expressions. These two expressions can be any two integer data types. Symbols of bitwise operators and their definitions are as follows:4.3.
Table4.3Bitwise operators
Operator
IncludingYi
( by bit and)
Bitwise AND operator ()
The two data involved in the operation perform the "and" Operation in binary bits.
Calculation rule: 0 0 = 0;0 1 = 0;1 0 = 0;1 1 = 1;
That is, if the two digits are "1" at the same time, the result is "1". Otherwise, the value is 0.
Example: 3 5That is, 0000 0011 0000 0101 = 0000 0001Therefore, 3 5 is worth 1.
In addition, negative numbers are involved in bitwise A
Binary OperatorsBecause data in the computer is in binary format, Java provides binary operators for direct operations. This is the bitwise operators and shift operators to be explained below.Binary operators can be used to operate numbers directly on the basis of binary. The execution efficiency is much higher than that of ordinary mathematical operators. These operators are widely used in network programming, hardware programming, and other fields.B
What functions can bitwise Operations implement?
What functions can bitwise Operations implement?
In many cases, bitwise operations are recommended to reduce the time complexity of the algorithm. Today, let's sort out the functions that bitwise operations can implement.
1. multiplication and division 2
Shift 1 to 2 a
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.