decimal number conversion

The base numbers are: binary (B), octal (O), decimal (D), and hexadecimal (H).

1. Decimal conversion to binary

Meaning: Integer conversion divide by 2 and take the remainder (reverse order). For decimals, the fractional part is multiplied by 2 and rounded up (order).

If there are integers and decimals, they are separated and taken.

Example:

Convert decimal to octal (every octal into one)

Meaning: It is the same as the conversion binary idea, but the type is different.

Example:

Convert decimal to hexadecimal (integer in reverse order, fractional part in order)

Meaning: The integer part is divided by 16 and the remainder is obtained until it is not divisible. Multiply the decimal by 16, round up, and then multiply the fraction by 16. until the given accuracy is met.

The method of converting R base to R base:

Convert binary to octal (take the three-in-one method, that is, from the decimal point of binary as the dividing point (four digits), add 0 to the front if there are not enough three digits, take a multiple of 3, and then replace it with octal code.)

Corresponding R code

Converting from binary to decimal

Binary to hexadecimal (take the four-in-one method to take every four digits from the left to make one digit, if it is not four digits, add 0 to the front to satisfy. Note that 4 digits are divided from the right first, that is, from the demarcation point, and then to the left push)

Octal to binary (split each number of octal integers, and combine the corresponding binary numbers of each number, and fill in 0 according to the number of digits. Note that if the middle number is not 0, it depends on the situation. )

Example:

Convert octal to decimal (same as binary to decimal)

Example:

Octal to hexadecimal:

There are 2 methods:

1. Convert octal to binary, and convert binary to hexadecimal

2. Convert octal to decimal, and convert decimal to hexadecimal

Convert hexadecimal to binary: (reverse according to the four-in-one method of binary to hexadecimal)

Example:

Hexadecimal to Octal (also)

There are 2 methods

1. Convert hexadecimal to binary, and convert binary to octal

2. Convert hexadecimal to decimal, and convert decimal to octal

Convert hexadecimal to decimal (same as binary and octal conversion to decimal)

Example:

So far!

Guess you like

Origin blog.csdn.net/weixin_44591600/article/details/120369303