Binary to Decimal Logic Circuit Principles

How does a computer convert binary to decimal? I’m talking about computers, I’m not asking about formulas, I’m asking about decoders!

The way a computer converts binary to decimal is by weight expansion. In a binary number, the weight of each bit is a power of 2. From right to left, the powers gradually increase, with the rightmost bit having a weight of 2^0=1, the second bit having a weight of 2^1=2, the third bit having a weight of 2^2=4, and so on. When a computer is processing a binary number, it multiplies the value of each bit by its corresponding weight, and then adds all the bit products to get the value after conversion to decimal. For example, the binary number 1101, the weight of each bit from right to left is 1, 2, 4, 8, so the value after conversion to decimal is 1 × 1 + 0 × 2 + 1 × 4 + 1 × 8 = 13.

1. Write out the weights corresponding to each bit of the binary number from right to left, and the weights start from 0 and gradually increase, and each bit’s weight is the nth power of 2, and n indicates that the position of the bit (bit 0 is the rightmost bit, bit n is the n+1st bit counted from right to left).

2. Multiply the value of each bit by the corresponding weight.

3. Add the product of all the bits to get the value after conversion to decimal.

Because binary numbers with hundreds of bits are relatively large, it is more cumbersome to calculate them manually, so you can use a calculator or a relevant function in a programming language to convert them. int(binary_str,2)print(decimal)

This code converts a binary number with a length of tens of digits to a decimal number and outputs the result.

Binary number converted to decimal

On the conversion of binary to decimal calculation method is:

1, unsigned integers, from right to left in order with the number of binary digits multiplied by the sum of the nth power of 2 (n is greater than or equal to 0);

2, signed binary integers, excluding the highest bit of the sign bit (1 is a negative, 0 is a positive), the rest of the same with the unsigned Binary to decimal conversion method is the same;

3, decimal binary to decimal number, from the decimal point on the first bit of the binary digits multiplied by 2 negative primary plus the second bit of the binary digits multiplied by 2 negative quadratic, and so on the nth bit of the binary digits multiplied by 2 negative n times.

Expanding Knowledge

It is well known that the base of binary is 2, and the 2 we divide when we decimalize binary is its base. Talking about its principle, it is necessary to talk about the concept of bit power. The numerical value of each digit in a certain system of counting represents the value of the digit multiplied by a constant related to the digit, which is called the “bit power”.

The size of the bit power is the base number as the base, the number of digit symbols in the position of the serial number for the exponent of the integer power. The power of the hundredth, tenth, first, and tenth digits of a decimal number is the 2nd power of 10, the 1st power of 10, the 0th power of 10, and the -1st power of 10, respectively. A binary number is the nth power of 2.

Is there any other number system in our life besides binary? In fact, there are many other number systems in our lives, such as our time 1 hour has 60 minutes, every 60 into 1, that is, hexadecimal, such as 1 week has 7 days, which is 7, and then for example, the old scales of a catty has 16, they use hexadecimal, so there is “half a catty, eight or two,” the saying.

Because binary numbers are the basic system for computers, it is easy to represent various values through the two states of 0 and 1, which makes the design of logic circuits simple.

Octal and hexadecimal are very convenient for the conversion of binary, and at the same time can be a larger number of binary to a shorter number of words to express, easy for people to write and record, so the use of octal and hexadecimal to express the binary number.