Original code, complement, inverse code and bitwise operation

Source: Internet
Author: User
Tags bitwise
original code, complement and inverse codeExample:-13, binary is-1101, using a byte to represent the original code: 10001101 complement: 11110011 anti-code: 11110010 Original Code Reverse code:The inverse code of a positive number is the same as the original code, such as 13 of the original code is 00001101, the inverse code is 00001101 negative code for the original code of the numerical part of the reverse, such as-13 of the original code is 10001101, the inverse code is 11110010 Original code transfer complementThe complement of a positive number is the same as the original code, such as 13 of the original code is 00001101, the complement is 00001101 negative complement to the original code of the numerical part of the inverse plus 1, such as-13 of the original code is 10001101, the complement is 11110011 Anti-code switch source codeThe original code for a positive number is the same as the reverse code

The original code of the negative number is the inverse of the value of the reverse code, such as-13 of the counter code is 11110010, then-13 of the original code is 10001101
complement to the original code of the complement of the original code with the same negative number of the original code for the value of the complement is added 1, such as-13 of the complement of 11110011, the original code is 10001101

-bit negation

Operation symbol ' ~ ', the binary of the number is reversed, the following assumes that all numbers in the computer using a byte representation

Example:

-13, binary representation is-1101, the complement is represented as 11110011

13 negation to 00001100, computer read 12

~ ( -13) =12 Move left

The operator symbol is ' << ', shifting the number of bits to the left, empty position 0

Example:

-13<<3:

-13 of the complement of 11110011, left three digits after 10011000, converted to the original code of 11101000

Computer interpretation of the -104 right shift operation symbol for ' >> ', the number of bits to the right shift, the empty position symbol bit example: -13>>3:-13 of the complement of 11110011, right three digits after 11111110, To the original code for 10000010 computer interpreted as-2 13>>3:13 of the complement of 00001101, the right three digits after 00000001, into the original code for 00000001 computer interpreted as 1 final results -13>>3=-2 13> >3=1 bit with bitwise AND example: the complement of the -13&7-13 is 11110011 7 with a 00000111 bitwise with the result of 00000011=3 or bitwise XOR or an example: -13^7-13 's complement The code is 11110011 7 of the complement of 00000111 bitwise XOR result is 11110100, the original code is 10001100=-12 bit or bitwise OR example: -13|7-13 's complement is 11110011 7 of the complement for 00000111-bit Or the result is 11110111, the original code is 10001001=-9

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.