C++ learning summary of binary conversion

  • 2020-04-02 03:08:16
  • OfStack

One, purpose: to facilitate computer representation, good stability, logical operation, true for 1, false for 0.

Ii. Representation of each base system:

Base 2:0,1

Base 8:0-7

Hexadecimal: 0-9, A,B,C,D,E,F

Ii. Conversion method:

1. Convert each base to 10:

Let's start with what we know best: base 10. Each of these Numbers add up to the 10n power. From right to left: a*100+b*101+c*102... The result is expressed as cba; Same thing with binary, octal, hexadecimal just replace 10 with 2,8,16.

2.10 to 2,8,16. Take the remainder and arrange it in reverse order.

3.8 base to base 2. The first thing to understand is that 2 is 1,8 is 1, and 16 is 1. 7 in base 2 requires three digits (three from right to left). Therefore, 8 - 2 is converted into "every (3 2 bits) into 1 (1 is less than 3 bits of 2 bits, and 0 is added in its high position)". Similarly, hexadecimal to hexadecimal to hexadecimal is the same.

The above is all the content of this article, I hope you can enjoy it.


Related articles: