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 does the javascript median operator mean?

2025-01-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article introduces the knowledge of "what does the median operator of javascript refer to". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

In javascript, bit operators are symbols used to manipulate binary bits, which can be aligned from low to high bits. The bit operators supported in JavaScript are "&", "|", "^", "~", ">".

The operating environment of this tutorial: windows7 system, javascript1.8.5 version, Dell G3 computer.

In javascript, bit operators are symbols used to manipulate binary bits.

The bit operator operates after aligning binary bits from low to high bits.

The bit operators supported in JavaScript are shown in the following table:

Operator description example & bitwise and: if the corresponding binary bit is 1, the binary bit is 15-1 equal to 0101-0001, the result is 0001, and the decimal result is 1 | bitwise OR: if one of the corresponding binary bits is 1, then the binary bit is 15 | 1 equals 0101 | 0001 results are 0101, and the decimal result is 5 ^ bitwise XOR: if only one of the corresponding binary bits is 1 Then the binary bit is 15 ^ 1 equal to 0101 ^ 0001, the result is 0100, and the decimal result is 4 ~ bitwise non: reversing all binary bits, that is, converting 1 to 0, converting 0 to 1, converting 0 to 0101, the result is 1010, the decimal result is-6 1 equals 0101 > > 1, the result is 0010, the decimal result is 2 > move zero to the right (unsigned right): move all binary bits to the right by the specified number of digits And on the far left, complement 05 > > 1 equals 0101 > 1, the result is 0010, and the decimal result is 2.

There are seven bit operators, which are divided into two categories:

Logical bit operators: bit and (&), bit or (|), bit XOR (^), non-bit (~)

Shift operator: shift left (), unsigned right (> >)

Logical bit operators (&, |, ^, and ~)

Logical bit operators operate in the same way as logical operators, but for different objects. Logical bit operators are for binary integer values, while logical operators are for non-binary values.

"&" operator

The "&" operator (bit and) is used to compare two binary operands bit by bit and return the results according to the conversion table shown in the following table.

The bit value of the first number of the "&" operator the result of the bit value operation of the second number 111100010000

In the in-place operation, the value 1 represents true,0 for false, and vice versa.

If 12 and 5 perform bit and operation, the return value is 4.

Console.log (12-5); / / return value 4

The following figure parses the process of bit and operation of 12 and 5 in the form of an expression. Through bit and operation, only the value of bit 3 is all true, so it returns true, and all other bits return false.

"|" operator

The "|" operator (bit or) is used to compare two binary operands bit by bit and return the result according to the conversion table shown in the table.

The bit value of the first number of the "|" operator the result of the bit value operation of the second number 111101011000

If 12 and 5 perform a bit or operation, the return value is 13.

Console.log (12 | 5); / / return value 13

The following figure parses the process of bit or operation of 12 and 5 in the form of an expression. By bit or operation, all bits return true except that the value of bit 2 is false.

"^" operator

The "^" operator (bit XOR) is used to compare two binary operands bit by bit and return the results according to the conversion table shown in the table.

The bit value of the first number of the "^" operator the result of the bit value operation of the second number 110101011000

If bitwise XOR is performed on 12 and 5, the return value is 9.

Console.log (12 ^ 5); / / return value 9

The following figure parses the process of bitwise XOR operations between 12 and 5 in the form of an expression. Through bit XOR, the values of bits 1 and 4 are true, and the values of bits 2 and 3 are false.

"~" operator

The "~" operator (bit is not) is used to reverse a binary Operand bit by bit.

Step 1: convert the Operand to a 32-bit binary integer.

Step 2: carry out the inversion operation bit by bit.

Step 3: convert binary inverse codes to decimal floating point numbers.

If a bit non-operation is performed on 12, the return value is-13.

Console.log (~ 12); / / return value-13

The following figure parses the process of bit non-operation of 12 in the form of an expression.

Bit non-operation is actually a negative operation on the number, and then minus 1. For example:

Console.log (~ 12 = = 12-1); / / returns true

Shift operator (and > >)

The shift operation is a regular low shift of the binary system. Shift operation can design many wonderful effects and is widely used in graphics and image programming.

">" operator

The ">" operator performs a signed right shift operation. In contrast to the left-shift operation, it shifts all the significant bits in the 32-bit number to the right as a whole, and then fills the space with the value of the symbolic bit. Values that are exceeded during the move are discarded.

If you move the value 1000 8 bits to the right, the return value is 3.

Console.log (1000 > > 8); / / return value 3

Demonstrate with a formula, as shown in the figure.

If you move the value-1000 8 bits to the right, the return value is-4.

Console.log (- 1000 > > 8); / / return value-4

Demonstrate with a formula, as shown in the figure. When the symbol bit value is 1, the space to the left of the significant bit is all filled with 1.

"> >" operator

The "> >" operator performs a five-symbol right shift operation. It moves all digits of unsigned 32-bit integers to the right as a whole. For the unsigned or positive right shift operation, the result of the unsigned right shift operation is the same as the signed right shift operation.

The return values of the following two lines of expressions are the same.

Console.log (1000 > > 8); / / return value 3console.log (1000 > > 8); / / return value 3

For negative numbers, the unsigned right shift will use 0 to fill all the spaces, and the negative number will be treated as a positive number, so the result will be very large, so be very careful when using the unsigned right shift operator to avoid unexpected errors.

Console.log (- 1000 > > 8); / / return value-4console.log (- 1000 > 8); / / return value 16777212

Demonstrate with a formula, as shown in the figure. The left space is no longer filled with the value of the symbol bit, but with 0.

That's all for "what does the median operator of javascript refer to?" Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

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