Title: Learn to use bitwise AND &.
Not the knowledge point, checked the bitwise operation.
A bitwise operator computes a number as a binary.
operator |
Description |
Example |
& |
Bitwise AND Operator: Two values that participate in the operation, if two corresponding bits are 1, the result of that bit is 1, otherwise 0 |
(A & B) Output result 12, binary interpretation: 0000 1100 |
| |
Bitwise OR operator: As long as the corresponding two binary has one for 1 o'clock, the result bit is 1. |
(A | b) output result 61, Binary interpretation: 0011 1101 |
^ |
Bitwise XOR Operator: When two corresponding binary differences, the result is 1 |
(a ^ b) output result 49, binary interpretation: 0011 0001 |
~ |
Bitwise inverse operator: each bits of the data is reversed, that is, 1 is changed to 0, and 0 to 1. ~x similar to -x-1 |
(~a) Output result-61, Binary interpretation: 1100 0011, in the complement form of a signed binary number. |
The representation of a Python binary:
- Binary: 0b
- Octal: 0o
- 16 Binary: 0x
Conversion of the binary:
Binary: Bin ()
Octal: Oct ()
Hex: Hex ()
The direct output is the decimal.
Python3 Exercises 100 Questions--051