In C language, the conversion between hexadecimal

Source: Internet
Author: User
Tags binary to decimal decimal to binary

In C language, the conversion between hexadecimal

Conversion between hexadecimal in C LanguageAuthor: Star)

 

Integer data can be expressed in the following ways:

Decimal: these nine digits are both 0-9 and cannot start with 0.

Binary: it consists of numbers 0 and 1.

Octal: it consists of 0-7 numbers. to distinguish it from other hexadecimal numbers, it starts with 0.

Hexadecimal: consists of 0-9 and A-F. To distinguish it from other numbers, it starts with ox.

 

1. Convert decimal to binary

Method: divide the decimal number by 2, and then take the remainder until the last quotient is 0 .. Then the remainder is obtained from bottom to top (this is the binary number)

 

2. Convert binary to decimal

Method: Expand and add the binary number in decimal format by weight.

 

Analysis: Binary four-digit number, starting from a single bit: 0.1.2.3 is

The number of digits multiplied by the power of 2 to 0 + ten digits multiplied by the power of 1 of 2 +Multiply the number of hundred BITs by the power of 2 and the number of thousandsThe number multiplied by the power of 2 = The number in decimal format

 

3. Convert decimal to octal (similar to decimal to binary)

Method: divide the number in decimal format by 8 until the quotient is 0, and then return the remaining eight digits.

 

 

4. Convert octal to decimal (similar to binary to decimal)

Method: calculate the number of octal nodes by weight,The sum is the decimal number.

 

5. Binary to octal

Method 1: Binary-> Decimal-> octal

The 3rd power of method 2 is 8. Therefore, the binary can start from a single bit and be split into three into a group. If the maximum number is less than 3, the value is 0 ..

Then the number of each group represents the single digit of the octal ..

 

 

Convert binary to hexadecimalThe same way

 

5. Convert octal to binary

Method 1: 8Base-> Decimal-> binary

Method 2: Perform the division of the remainder for each bid in octal. If the remainder is not three, add 0 in the highest position. (Why are less than 3Add 0 at the highest bit? Because the power of 2 is 8).

 

 

 

The same is true for hexadecimal to binary.

 

Related Article

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.