How bitwise operators are negated in C

Updated on technology 2024-08-06
18 answers
  1. Anonymous users2024-02-15

    1010 inverse code.

    is 0101 and negative numbers are represented in the computer by using complement, -11 to find the complement process: 1011 is negated by ->0100 plus 1->0101

    i.e. -11 is equivalent to 10

    In parentheses is 0101

    Supplementary note: Yes, the storage of 1010 in the 32-bit computer is actually 00001010, after the negation is 11110101, the first place in the computer is 0 means a positive number, is 1 means a negative number, that is, the 11110101 represents a negative number, that is, to find this negative number by the 11110101, that is, to find the inverse of the complement, steps: first subtract 1 to get 11110100, and then take the inversion, when the sign bit is unchanged, get the 10001011, that is, -11.

    If it is represented by 4 digits, you can enter 0101 or 8 digits of 11110101

  2. Anonymous users2024-02-14

    A is an int type.

    Typically 4 bytes.

    Original code of 2: 0000

    Negation: The highest digit is 1 so it is a negative number, find its original data, the method is.

    Cancel again plus 1 (the sign bit is unchanged) and take the neg:

    Plus 1 so yes.

  3. Anonymous users2024-02-13

    bit" operator, is a lie.

    Actually, it is calculated according to a [character].

    The negation is to use "1" as an "XOR" operation.

  4. Anonymous users2024-02-12

    1 for 1 for both and 0 for otherwise.

    1&1=1,1&0=0,0&1=0,0&0=0,0&0=0 or arithmetic:|

    0 is 0 for both, 1 for otherwise

    1|1=1,1|0=1,0|1=1,0|0=0 non-op:

    1 takes 0, 0 takes 1

    XOR operations. The two are equal to 0 and the unequal is 1

  5. Anonymous users2024-02-11

    Hexadecimal to binary doesn't need to do this, just turn each hexadecimal into 4-bit binary, so.

    11(16) = 0001 0001(2) 0x11 This 0x11 is an integer constant.

    So = 0x 0011

    0xffee

  6. Anonymous users2024-02-10

    0x11 = 0x0011 = 0000 0000 0001 0001 (no need to convert to decimal and then to binary, it's too troublesome, a 16-base bit can be directly converted into a four-digit binary bit).

    If you reverse it, you will get 1111 1111 1110 1110, which is 0xffee

    The key to the problem is to make up for the bits, and the previous 0 can't be saved.

  7. Anonymous users2024-02-09

    Let's start with the boolean value of and, or, XOR, and inverse:

    and arithmetic, both are true, and the result of the computation is true, and vice versa is false:

    or arithmetic, at least one of which is true, and the result of the calculation is true, and vice versa:

    XOR operation, the difference between the two is true, and the opposite is false orange front:

    1 ^ 1 = 0,1 ^ 0 = 1,0 ^ 1 = 1,0 ^ 0 = 0;Dan is missing.

    Take the negation operation, monocular operator:

    Example 1 above is true and 0 is false.

    Bitwise arithmetic is to perform the above calculation on each bit of the binary bit.

    Such as 2 |5, Convert to binary (take 1 byte 8 bits as an example):

    00000010 |00000101, each binary bit is performed separately or arithmeticed

    00000111 i.e. 7. While 7 = 5 + 2, it doesn't mean 2| 5 = 2 + 5。

    Such as 2 | 6 = 6,5 | 6 = 7,2 | 4 | 5 | 6 | 7 = 7。

    In the same way, bitwise and operations 2 & 5 result in 0:

    Bitwise with the result of operations 2 & 6 is 2 (binary 00000010):

    The same can be calculated for 2 6 as 4 (binary 00000101):

    Inverse operation 00000110 = 11111001.

    Of course, the result of negating a number is also related to whether the type is a sign or an unsigned, the size of the bytes occupied, and so on. The above example is just a byte to illustrate.

  8. Anonymous users2024-02-08

    Essentials:

    1.Students who do not know binary and decimal conversion click here to learn.

    2.The first bit in binary is the sign bit, 0 is a positive number, and 1 is a negative number, e.g. 0000 0001 is +1 and 1000 0001 is -1.

    3.When the system calculates the inverse of the complement, the sign bit remains unchanged, and we manually use the operator to inverse when the sign bit changes, which is why positive numbers are inversely negative numbers, and negative numbers are inversely inverse to positive numbers.

    Don't look at me, I'm an emotionless dividing line

    First of all, determine one thing, negation is to convert the number into binary, and then turn 1 in binary into 0 and 0 into 1.

    So how do you explain e.g. 10=-11?

    This starts with the way binaries are stored. Computers do not store binary source code directly, but rather binary complements. The complement of positive numbers is the original code, such as 1, the original code 0000 0001, and the complement code is also 0000 0001.

    The complement of negative numbers is "the sign bit remains unchanged, and the original code is reversed and then added by one" (after all, the computer is not a human being, and it needs to artificially embed a perfect set of rules.) This storage method has rigorous mathematical proof, and interested students can look it up on the Internet on their own. For example, -1, the original code is 1000 0001, the inversion is 1111 1110, and 1111 1111 is the binary complement of -1.

    When the negative number is output, the complement is reversed into the original code, and the original code is reversed and added to get the complement, and the complement is subtracted by one to get the original code.

    Don't look at me, I'm still an emotionless dividing line

    Next, let's get down to business.

    Decimal, the number 10

    The binary source code is the complement code 0000 1010 and is stored directly.

    After 10, the original code (complement) becomes 1111 0101

    Since his sign bit is 1, the system considers this to be a negative complement.

    When the negative number is output, first subtract the complement by one to get 1111 0100, and then take the reverse to get 1000 1011

    When converted to decimal, it is -11.

    Don't you think it's almost interesting? Let's take another example of a negative number.

    Decimal, the number -5

    Binary source code 1000 0101

    Take the complement (remember the negative complement?) The symbol bit remains unchanged, and the original code is reversed and added by one) 1111 1011

    -5), i.e. 0000 0100 after negation

    Since his sign bit is 0, the system assumes that this is a positive complement.

    The positive complement code is the original code, and the final output is 0000 0100

    Converted to decimal is 4.

    **I'm different from the two dividing lines above, I'm emotional, and now I'm going to zoom in***

    A simple way to negate operations.

    It can also be said to be a calculation method suitable for human calculations:

    If a is bitwise negated, the result is -(a+1).

    This operation applies to both positive numbers, negative numbers, and zeros.

  9. Anonymous users2024-02-07

    Start by looking to the left of the equal sign.

    100) is expressed as follows: 0110 0100 bitwise negation means that every bit is negated, 0 becomes 1, 1 becomes 0 so:

    The binary representation of 100 is: 1001 1011, so the left of the equal sign = 1001 1011

    Look to the right again. 101.Once you see a negative number, then the number must be represented according to the rule of signed numbers. A binary number is bitwise negated and added to one to get its own negative complement, i.e.

    x+1=-x

    So, let's add 101 to the bits of inverted plus one. First negation:

    Add one more: so the right side of the equal sign = 10011011 = left, so the equal sign holds.

    To add, the logical storage bits in a computer's memory are very complex, and even if I explain it clearly, I can't guarantee that you will understand it completely.

    In general, assembly language books will explain this knowledge in detail at the beginning of the book in order to serve assembly language, see it.

  10. Anonymous users2024-02-06

    077o=11000000b is not wrong, but in computers, integers are represented using complements. The complement of a positive number is the same as the original code, while the complement of a negative number is represented by a negative number with the highest digit of 1, and the rest of the lower digits are represented by adding the absolute value of the negative number to 1 inversely.

    For example, -64d, if it is represented by 8-bit binary complement, the highest bit is 1 to represent a negative number, and the remaining 7 bits will be the absolute value of -64d 64d = 1000000b, and the inverse plus 1 is 1000000, and the signature bit (highest bit) 1 is spliced to 11000000, so 11000000 means -64d. (The suffix o represents an octal number, d represents a decimal number, and b represents a binary number).

  11. Anonymous users2024-02-05

    Yes, -64, and this number is stored in memory in the form of 11000000. Your understanding is correct, but the point is that you don't know that negative numbers are stored in memory in the form of complements.

    The original code of 64 is minus 1000000, the reverse code is the negative 0111111, the complement code is the inverse code +1 = 1000000, and the negative sign in front of it is 1, so it is 11000000, so this number is -64

  12. Anonymous users2024-02-04

    Let me explain it to you in detail:

    The binary of 12 is as follows: 00001100

    After negation: 11110011 This is a negative form of complement, but which negative complement is this?

    Let's first look at how the complement of a negative number is represented. [The complement of a negative number is the negation of its original code bit by bit, except for the sign bits; Then add 1 to the whole number. 】

    Let's go back and get it:

    First put 11110011-1=11110010

    Then the sign is negated outside the sign: 10001101

    Look at the number in addition to the symbol: 0001101 is 13 so this number is -13

    So: 12=-13

    Find the complement of -7. 】

    Since a given number is negative, the sign bit is "1".

    The last seven digits: -7 of the original code (10000111) bitwise negation (11111000) (negative sign bit unchanged) plus 1 (11111001).

    So the complement of -7 is 11111001.

    Knowing the complement of a number, there are two ways to find the original code

    1) If the sign bit of the complement is "0", it means that it is a positive number, and its original code is the complement.

    2) If the symbol bit of the complement is "1", which means that it is a negative number, then finding the complement of the given complement is the required original code.

    Here's another example: find the complement of -64.

  13. Anonymous users2024-02-03

    Assuming that integers are represented in 16-bit binary, then.

    The original code of 9 is: 0000000000001001

    The value of 9 is: 1111111111110110 -- this is exactly the complement of -10.

  14. Anonymous users2024-02-02

    0000 0000 0000 1001 is reversed to 1111 1111 1111 0110, which is the complement of 0000 0000 0000 1010.

    i.e. -10

  15. Anonymous users2024-02-01

    Binary Decimal.

    > hope it helps.

  16. Anonymous users2024-01-31

    Negative numbers are inverted by bits, and then +1

  17. Anonymous users2024-01-30

    The general way to calculate bitwise negation:

    The number to be calculated is expressed in binary system, with a minimum number of binary digits plus 1 (1 more sign bit) that can represent the absolute value of the current number. That is, 9 is represented as 01001, where the leftmost 0 is the sign bit, 0 is positive, and 1 is negative.

    Negate each binary bit, and if it is 1, the result is 0, and if not, the result is 1. The result is 10110

    Think of the result as a signed number, convert it to decimal. The leftmost digit is the sign bit, and the 1 is negative. In computers, negative numbers are represented by complements, and the signed number 10110 is converted to decimal system, which is -10

    A simple algorithm for calculating bitwise negation.

    Subtracting the number to be negated by -1 gives the result of bitwise negation: -1-9=-10

  18. Anonymous users2024-01-29

    Let's start with the boolean value of and, or, XOR, and inverse:

    and arithmetic, both are true, and the result of the computation is true, and vice versa is false:

    or arithmetic, at least one of which is true, and the result of the calculation is true, and vice versa:

    XOR operations, the difference between the two is true, and the opposite is false:

    Take the negation operation, monocular operator:

    Example 1 above is true and 0 is false.

    Bitwise arithmetic is to perform the above calculation on each bit of the binary bit.

    Such as 2 |5, Convert to binary (take 1 byte 8 bits as an example):

    00000010 |00000101, each binary bit is performed separately or arithmeticed

    00000111 i.e. 7. While 7 = 5 + 2, it doesn't mean 2| 5 = 2 + 5。

    Such as 2 | 6 = 6,5 | 6 = 7,2 | 4 | 5 | 6 | 7 = 7。

    In the same way, bitwise and operations 2 & 5 result in 0:

    Bitwise with the result of operations 2 & 6 is 2 (binary 00000010):

    The same can be calculated for 2 6 as 4 (binary 00000101):

    Inverse operation 00000110 = 11111001.

    Of course, the result of negating a number is also related to whether the type is signed or unsigned, the size of the bytes occupied, and so on. The above example is just a byte to illustrate.

Related questions
18 answers2024-08-06

Using Liu Hui's "circumcision" formula, I calculated pi—— >>>More

19 answers2024-08-06

: has a higher priority than =

Below << >>>More

5 answers2024-08-06

n |= 1 is equivalent to n = n | 1

Operator |It's bitwise or arithmetic, you can write two operands as binary first, and then look at them, for example, binary numbers. >>>More

12 answers2024-08-06

> operator (c reference).

The Shift Right operator (> moves the first operand to the right by the number of bits specified by the second operand. >>>More

7 answers2024-08-06

+ Follow the right binding rule;

a=++i++;Equivalent to int temp=i++, a=++temp; >>>More