Basic: hexadecimal conversion

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

Labels: style blog HTTP color SP strong data on 2014

 

1. What is binary, octal, decimal, and hexadecimal?

What we usually use in our daily life is a 10-digit system, that is, every 10-to-1;

  Binary: Every two to one is composed of 0 and 1;

  Octal: Every eight to one is composed of 0 to 7; the numbers starting with "O" in front indicate that the octal sequence uses % O in C.

Decimal: Every 10 to one is composed of 0-9.% d is used in C.

  HexadecimalEach hex consists of 0-15, 10-15 corresponds to the A-F, respectively; the number starting with ox in front of the hexadecimal representation in C Language % x

 

2. Conversion between binary, octal, hexadecimal, and decimal

(1) convert binary, octal, and hexadecimal to decimal

Decimal expression: (12345) 10 = 1*104 + 2*103 + 3*102 + 4*101 + 5*100 = 12345

Octal to decimal: (12345) 10 = 1*84 + 2*83 + 3*82 + 4*81 + 5*80 = 5349

Binary to decimal: (10101) 10 = 1*24 + 0*23 + 1*22 + 0*21 + 1*20 = 21

Hexadecimal to decimal: (1f2a5) 10 = 1*164 + 15*163 + 2*162 + 10*161 + 5*160 = 127653

(2) convert decimal to binary, octal, and hexadecimal

Decimal to binary: divide the decimal number by 2 until the divisor is less than 2, and then sort the remainder in reverse order.

25/2 --------- 12 + 1

12/2 --------- 6 + 0

6/2 --------- 3 + 0

3/2 --------- 1 more than 1

1

In reverse order, the result is (25) 2 = 11001.

Decimal to octal: similarly, the number in decimal order is divided by 8 until the divisor is less than 8, and then the remainder is sorted in reverse order.

168/8 ---------- more than 16 0

16/8 ---------- 2 + 0

2

(168) 8 = 200

Decimal to hexadecimal: Similarly, the number of decimal is divided by 16 until the divisor is less than 16, and then the remainder is arranged in reverse order, the number greater than 10-15 is represented by a A-F

127653/16 ---------- 7978 + 5

7978/16 ---------- 498 more than 10 (10 expressed as)

498/16 ------------ 31 + 2

31/16 ------------ more than 1 15 (15 expressed in F)

1

(127653) 16 = 1f2a5

 Supplement:Use a program to convert any ten-digit integer into a binary and hexadecimal tree (this is my machine question for going to the Hypergraph. I implemented it in C # at the time, and I will use C language below)

3. Mutual conversion between binary and octal

Binary represents the octal value, and binary represents the octal value with three digits (23 = 8), as shown below:

Binary octal

000 0

001 1

010 2

011 3

100 4

101 5

110 6

111 7

  (1) convert octal to binary: replace the number of octal values into three binary values.. As follows:

123 = 001 010 011 = 1010011

(2) binary to octal: from the low position to the high position, it is divided into three groups. If the high position is not three, it is filled with 0, and then the three binary digits are replaced with octal values.. As follows:

(1010011) 8 = 1 010 011 = 001 010 011 = 123

4. Mutual conversion between binary and hexadecimal

Binary represents the hexadecimal notation, and binary represents the hexadecimal notation with four digits (24 = 8), as shown below:

Binary hexadecimal binary hexadecimal

0000 0 0001 1

0010 2 0011 3

0100 4 0101 5

0110 6 0111 7

1000 8 1001 9

1010 A 1011 B

1100 C 1101 d

1110 e 1111 F

(1) hexadecimal to binary: convert each hexadecimal number to a binary value of four digits.As follows:

(1a2b3c) 2 = 0001 1010 0010 1011 0011 1100 = 110100010101100111100

  (2) binary to hexadecimal: from the low position to the high position, it is divided into four groups. If the high position is not 4, it is filled with 0, and then the four binary digits are replaced with the hexadecimal number.. As follows:

(110100010101100111100) 16 = 1 1010 0010 1011 0011 1100 = 1a2b3c

5. Decimal hexadecimal conversion

6. storage of data on computers

7. Principles of Data Types

 

......

[C language basics] understand why

Basic: hexadecimal 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.