Python Encounters--symbolic operations (I.)

Source: Internet
Author: User

1. Boolean operators

A total of three

Not

Logical Take back Eg:not 1 return False

and

Object with priority return False value Eg:1 and 0 return 0 and return 12

Or

Returns the Truth object first Eg:1 or 2 return 1 0 or Return20

2, bit arithmetic

& | ^ << >> ~

&: Bitwise AND operation

Entering the same value returns the same value, and returns 0 for different values

Eg:7 & 7 return 7 8 & 9 return 0

|: Bitwise OR OPERATION

Returns true if the input has a true value, and returns 0 if two false values are entered

Eg:2 | 3 Return 2 0 | 0 return 0

^: Bit xor or

The same is 0, the difference is 1

Eg:2 ^ 3 return 1 2 ^ 2 return 0

<<: Shift left

Shift to left after counting to binary number, 0 for low

x << y shift x to the left Y-bit after binary number

Eg:2 << 3 Return 16

>>: Move right

Shift to the right after counting to binary, and low to discard

x >>y will shift x to the binary number and right y bit

Eg:2 >> 1 return 1

~: Bitwise REVERSE

Learn about the knowledge points before you know the bitwise inversion

(1) The reverse operation is carried out on the original code!

(2) in the computer, the number is in the complement of the storage, but converted to other binary requirements of the original code

(3) The original code to complement: Take the reverse, +1

(4) complement seeking the original code: reverse, +1

(5) Positive complement is the source code, the complement of negative numbers for its corresponding positive binary representation of all the bit inversion (including the sign bit, 0 change to 0) plus 1

When the input is a positive number, seek its complement (that is, its original code), and then take the reverse, and then seek the original code, you can get reversed (symbol band)

Eg:~5

5 of the complement is 0000 0101 to get 1111 1010, visible inverse number is a negative (binary highest bit symbol, 1 is negative, 0 is positive), and then the original code to 0000 0110, and then converted to decimal number 6

When the input is negative, seek its complement (that is, the number of positive numbers after 1), and then take the reverse, and then seek the source code, you can get the number of reversed (symbol band)

Eg:~-6

-6 of the complement of 6 of the original code to take the reverse +1,6 the original code is 0000 0110, take the reverse +1 after the 6 complement 1111 1010, and then take the inverse 0000 0101, it is shown that the inverse is a positive number, and then the original code to 0000 0101, and then converted to decimal 5

  

Python Encounters--symbolic operations (I.)

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.