Integer and binary conversion, binary addition calculation

How to convert integer 7 to binary

The method of converting the integer 7 into binary is: continuously obtain the quotient after dividing by 2 until the quotient is 0, and arrange the remainder obtained in each step in reverse order to obtain the corresponding binary number.

The quotient of 7 divided by 2 is 3 with a remainder of 1, the quotient of 3 divided by 2 is 1 with a remainder of 1, and the quotient of 1 divided by 2 is 0 with a remainder of 1.

The binary number obtained by arranging the remainder in reverse order is 111, so the binary representation of 7 is 111.

How to convert 10100 to integer 20

The method of converting the binary number 10100 to a decimal number (integer 20) is: expand from right to left according to the weight, multiply the value of each digit by the corresponding weight, and then add up all the results.

10100 represents a binary number, so it needs to be expanded according to the weight of the binary number:

    1      0      1      0      0       (各位上的数值)
 2^4    2^3    2^2    2^1    2^0       (各位上的权值)

Multiply the values ​​on each bit by the corresponding weight and add the results:

1×2^4 + 0×2^3 + 1×2^2 + 0×2^1 + 0×2^0 = 16 + 0 + 4 + 0 + 0 = 20

Therefore, the decimal number represented by the binary number 10100 is 20.

How to calculate the sum of the binary numbers 1011 and 1001 

 

The sum of the binary numbers 1011 and 1001 is 10100, which is 20 in binary.

The specific calculation method is as follows:

  1. First, align the two binary numbers bit by bit, and fill in the high bit with 0 if the number of digits is insufficient:

    1011

  •   1001

10100

  1. Add bit by bit starting from the lower bit, taking into account the carry generated by the previous bit. Calculate according to the following rules:
  • 0 + 0 = 0, no carry.
  • 0 + 1 = 1, no carry.
  • 1 + 0 = 1, no carry.
  • 1 + 1 = 0, with carry.

In this example, from low to high are: 1+1=10 (carry 1), 1+0+1=10 (carry 1), 0+0+1=1 (no carry), 1+1= 10 (carry 1), 0+0+1=1 (no carry). Therefore, the sum of the binary numbers 1011 and 1001 is 10100, which is 20 in binary.

Guess you like

Origin blog.csdn.net/weixin_42550871/article/details/130618352