Python3 Exercises 100 Questions--051

Source: Internet
Author: User
Tags bitwise

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

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.