C# ~ bitwise negation operator

      I used ~ (bit-wise negation operator) today, and I am a little confused about some explanations I found on the Internet. It is said on the Internet that it is enough to convert it into binary, including all the sign bits, but it is always the same as the result calculated by myself. It is not the same, and it is said that this is the complement form of a signed binary number, which is not particularly understood. After many searches, I will share with you some of my own understanding. Next, I will use a number as an example to talk about the specific process of the operation. There may be some misunderstandings. Please correct me! When it comes to ~ (non-operation), we have to talk about the complement of the original code. Everyone knows that the way the computer stores data is stored in the form of binary, and the complement of the original code appears to facilitate computer operations. in binary form. // ~(Negative operation) Bit logical NOT operation performs a bitwise negation on the value of the operand 
 // Computer operations are calculated in the form of complement code~ The symbol is to find the inversion of the complement code of the number The original code of 
 //Take 6 as an example: 
 // Original code: Complement code: Complement code: (positive numbers are the same (plus sign bit)) 00000110 
 // ~The operation logic of characters, first take 6's complement 00000110
 // Then take the inverse to get 11111001 (this is a complement) and then find the original code of the complement (the number is the complement of a negative number)
 // Find the original code 10000111 in the complement of a negative number ( The decimal expression is -7)
 //Take -6 as an example:
 // Original code: 10000110
 // Inverse code: 11111001
 // Complement code: 11111010
 //~ The operation logic of the character first takes the -6's complement 11111010 
 / / Take the opposite of 00000101 (this one's complement representation) 

 // In seeking its complement form, I get the original code 00000101 (decimal notation means 5) (this is a positive number: the original negation complement is the same) The above are some of my own opinions, I hope I can give you some help, of course If there are any shortcomings, please correct me! ! !

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324690713&siteId=291194637