C language Decimal turn octal, hexadecimal, decimal and hexadecimal turn, octal

The following procedure is output
main () {

int a=20;

printf("%d,%o,%x\n",a,a,a);

}
To see this topic we need to understand% x% o and representatives of what it means

% O is represented by the output octal numbers

% X is represented by the digital output hexadecimal

1. The title of this gives a = 20 decimal Now we need to turn in decimal octal, here we use is the direct addition to the modulo 8 ways

2. Similarly to turn hex decimal we also take 16 to take a method other than the

3. On the contrary, if we have a hex so how to decimal, octal it? Consider the following explanation

(1) hex decimal turn

Bit 0 weight hexadecimal value of 0 th to 16, a first power weight value of 1 to 16, the two weights is a power of 2 ...... 16

Example: 2AF5 converted to decimal 10:

With vertical calculation:

Bit 0: 0 = 5 * 16 ^ 5

Bit 1: F * 16 ^ 1 = 240

Bit 2: A * 16 ^ 2 = 2560

Bit 3: 2 * 16 ^ 3 = 8192

Direct calculation is:

5 * 16^0 + F * 16^1 + A * 16^2 + 2 * 16^3 = 10997

(2) hex binary transfer

Since the binary representation, the maximum value of each of the four corresponding to the number represented by hexadecimal 15, i.e. a maximum value of each hexadecimal, therefore, we can draw simple conversion method, the hexadecimal on each one made respectively on four binary conversion, i.e., that which is required:

Example: 2AF5 converted to a binary:

Bit 0: (5) = 16 (0101) 2

Bit 1: (F) 16 = (1111) 2

Bit 2: (A) 16 = (1010) 2

Bit 3: (2) 16 = (0010) 2

Obtained: (2AF5) 16 = (0010.1010.1111.0101) 2

(3) from hexadecimal octal

First hexadecimal into binary, then Binary to octal

 

 

 

 

 

 

 

He published 196 original articles · won praise 581 · views 470 000 +

Guess you like

Origin blog.csdn.net/wyf2017/article/details/104882436