In C language, the ~ symbol represents a logical NOT operation (bitwise inversion), which inverts the binary bits in the operand, changing 0 to 1 and 1 to 0.
~1 represents in C language
In C language, ~
The symbol represents the logical NOT operation (bitwise negation). It inverts each binary bit in the operand, i.e. 0 becomes 1 and 1 becomes 0.
Syntax:
<code class="c">~operand</code>
Among them, operand
is the expression to be bitwise inverted.
Example:
<code class="c">int x = 5; // 二进制表示:0101 int y = ~x; // 二进制表示:1010</code>
In this case, the value of y
is -6 because the binary representation after bitwise negation is 1010
, converted to decimal is -6.
Note:
~
The operator has a higher priority than other arithmetic operators (such as addition, subtraction). The ~
operator can be applied to any integer type of data, including int
, long
, and short
. The above is the detailed content of ~What does 1 mean and how to express it in C language?. For more information, please follow other related articles on the PHP Chinese website!