Conversion between binary, octal, decimal, hexadecimal numbers

Source: Internet
Author: User

One or two binary number converted to decimal number

The basic practice of converting a binary number to a decimal number is to first write the binary number as the weighted coefficient expansion, and then sum it by the decimal addition rule. This practice is known as the "weighted addition" method.

Function to convert binary to decimalint binary_decimal (int num) {int dec = 0, base = 1, REM;        while (num > 0) {rem = num% 10;        Dec = Dec + rem*base;        base = base*2;    Num/= 10; } return Dec;

Second, decimal number converted to binary number

Function to convert decimal to binaryint decimal_binary (int num) {int REM, base = 1, binary = 0;        while (num! = 0) {rem = num% 2;        Num/= 2;        binary + = Rem*i;    Base *= 10; } return binary;}

Three or two conversion between binary number and octal number

Four or two binary and 16 binary conversions

Conversion between binary, octal, decimal, hexadecimal numbers

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.