Fast conversion between hexadecimal and binary

We often use the decimal system in life, but computers are used to binary numbers. In order to avoid the complicated 01 string, the hexadecimal number is often shown to the programmer to operate.

1. Fast conversion of decimal numbers to hexadecimal and binary numbers

The common method of base conversion is to divide by two and take the remainder, and take the remainder from bottom to top . Also band recording method where a fast conversion achieved:
decimal binary switch, for example, for example 80转二进制:
Insert picture description here
80 + 16 can be divided into 64, the binary number 16 and the shaft 64 is above 1, the remaining bits 0s
calculator authentication:
Insert picture description here
and then Take 70为例: The
Insert picture description here
same is true for converting decimal to hexadecimal.

2. Fast conversion between hexadecimal and binary

There is a special relationship between hexadecimal and binary: the four digits of a binary number are equivalent to one hexadecimal number . Therefore, we can use this feature to quickly convert it to 十六进制数8F为例:
Insert picture description here
treat each digit as a decimal number and convert it to a four-digit binary number, and finally combine the results to get the answer.
Calculator verification:
Insert picture description here

Guess you like

Origin blog.csdn.net/m0_46550452/article/details/107742715