Python's binary conversion

Source: Internet
Author: User

2 binary 8 binary 10 binary 16 binary
2 binary - Bin (int (x, 8)) Bin (int (x, 10)) Bin (int (x, 16))
8 binary Oct (int (x, 2)) - Oct (int (x, 10)) Oct (int (x, 16))
10 binary int (x, 2) int (x, 8) - int (x, 16)
16 binary Hex (int (x, 2)) Hex (int (x, 8)) Hex (int (x, 10)) -

Example:

Number = 10Number_bin=Bin (number) Number_oct=Oct (number) Number_hex=Hex (number)Print("---------------Decimal Conversion-----------------------------")Print(Number,"The binary representation of the corresponding binary is:", Number_bin)Print(Number,"The corresponding octal representation is:", Number_oct)Print(Number,"The corresponding hexadecimal representation is:", Number_hex)Print("---------------binary Conversion-----------------------------")Print(Number_bin,"The corresponding decimal representation is:", Int (Number_bin, 2))Print(Number_bin,"The corresponding octal representation is:", The Oct (int (number_bin, 2)))Print(Number_bin,"The corresponding hexadecimal representation is:", Hex (int (Number_bin, 2)))Print("---------------octal Conversion-----------------------------")Print(Number_oct,"The corresponding decimal representation is:", Int (NUMBER_OCT, 8))Print(Number_oct,"The binary representation of the corresponding binary is:", Bin (int (number_oct, 8)))Print(Number_oct,"The corresponding hexadecimal representation is:", Hex (int (NUMBER_OCT, 8)))Print("---------------16 binary conversion-----------------------------")Print(Number_hex,"The corresponding decimal representation is:", Int (Number_hex, 16))Print(Number_hex,"The binary representation of the corresponding binary is:", Bin (int (Number_hex, 16)))Print(Number_hex,"The corresponding octal representation is:", Oct (int (number_hex, 16)))

Python's binary conversion

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.