Go directly to the code!
1<script type= "Text/javascript" >2 //JavaScript Operators3 //1, bitwise NOT ~4 varnum1=25;//5 varNUM2=~NUM1;//6 alert (num2)7 8 varnum3=10;9 varnum4=~num3;Ten alert (NUM4) One A varnum5=99; - varnum6=~NUM5; - alert (NUM6) the - //Note: I believe you have also seen the implementation of the bitwise ~ (not) principle: - //take NUM1, num2 as the explanation object - //First step: convert NUM1 to binary first + //Step two: Get num1 binary Inverse code assignment to num2 - //Step Three: Convert the num2 into decimal digits + //A simple explanation: minus 1 of the number of operands A at - //2, Bitwise AND & (and) - varRESULT=25 & 3; -alert (result);//1 - //The explanation is to convert two numbers into binary numbers, according to certain rules: - //Bit result of the second number of bits of the first numeric value in //1 1 1 - //1 0 0 to //0 1 0 + //0 0 0 - the //In short, the corresponding bit of the bitwise operator is 1 o'clock returns 1, and any one is 0 returns 0. * //and then convert the resulting binary into decimal digits. $ //25=0000 0000 0000 0000 0000 0000 0001 1001Panax Notoginseng //3= 0000 0000 0000 0000 0000 0000 0000 0011 - // ------------------------------------------ the //and=0000 0000 0000 0000 0000 0000 0000 0001 + A the //3, bitwise OR | (OR) + varresult=25 | 3; -alert (result);// - $ //The explanation is to convert two numbers into binary numbers, according to certain rules: $ //Bit result of the second number of bits of the first numeric value - //1 1 1 - //1 0 1 the //0 1 1 - //0 0 0Wuyi the //in short, a bitwise operator corresponds to a bit that has a 1 return of 1, and returns 0 only if two bits are 0. - //and then convert the resulting binary into decimal digits. Wu - //25=0000 0000 0000 0000 0000 0000 0001 1001 About //3= 0000 0000 0000 0000 0000 0000 0000 0011 $ // ------------------------------------------ - //or=0000 0000 0000 0000 0000 0000 0001 1011 - - A //4, Bitwise XOR or ^ (XOR) + varresult= 25 ^ 3; thealert (result);// - - //The explanation is to convert two numbers into binary numbers, according to certain rules: $ //Bit result of the second number of bits of the first numeric value the //1 1 0 the //1 0 1 the //0 1 1 the //0 0 0 - //in short, this operator (^) returns 1 only one 1 o'clock on the corresponding bit of two values, otherwise returns 0. in //and then convert the resulting binary into decimal digits. the the //25=0000 0000 0000 0000 0000 0000 0001 1001 About //3= 0000 0000 0000 0000 0000 0000 0000 0011 the // ------------------------------------------ the //xor=0000 0000 0000 0000 0000 0000 0001 1010 the + - //5. Shift Left (<<) the varoldnum=2;Bayi varNewnum=oldnum << 5; the alert (newnum) the //Note, move 2 (binary digit 10) to the left 5 bits result is 1000000 (binary) equals - //Note that the left shift does not affect the sign bit of the operator, such as moving 2 to the left 5 bits is -64 - //2=0000 0000 0000 0000 0000 0000 0000 0010 the //64=0000 0000 0000 0000 0000 0000 010 00000 the the the //6. Sign right Shift (>>) - varOldnum=64; the varNewnum=oldnum >> 5; the //64=0000 0000 0000 0000 0000 0000 010 00000 the //2=0000 0000 0000 0000 0000 0000 0000 001094 alert (newnum) the</script>
View Code
javascript--operators (~, &, |, ^, <<, >>)