Bluetooth communication will be involved decimal conversion, high and low bit (bit operation)

Bluetooth is a hexadecimal

10 hexadecimal to hexadecimal turn left high (higher 8 bits) and right lower (lower 8 bits)

 

When we touch programming knowledge, always in contact with the relevant knowledge base for the conversion, the most common is the conversion between decimal and binary or hexadecimal, many times we always forget, although there have been plenty direct use of network online binary conversion tool, but the exam, we have to rely on themselves through the formula calculation. Today would like to share knowledge about the theoretical base for the conversion, we can find common ground from the inside by contrast, it is easy to understand that we remember.

Before explaining, let's put a correspondence table below, since the understanding of the following conversion, you can view the list at any time.

 

A conversion between binary and decimal

(1) convert decimal to binary, is divided into an integer part and fractional part integer part ① Method: 2 modulo addition method, i.e., divided by two every time the integer portion of the number of bits in the weights for the remainder, divided by the supplier to continue 2, and the remainder is the number on the right a bit, this step has been sustained until the quotient is zero so far, when the last reading, reading from the last more than a number, up to the front of a remainder. The following Example: Example: A 168 decimal to binary outcome of the decimal to binary 168, (10101000) 2 analysis: the first step 168 divided by 2, supplier 84, the remainder is 0. The second step, the quotient 84 divided by 2, quotient 42 and the remainder is 0. The third step, the quotient 42 divided by 2, quotient 21 and the remainder is 0. The fourth step, the quotient 21 divided by 2, the quotient 10 and the remainder is 1. The fifth step, the quotient 10 divided by 2, 5 quotient remainder is 0. The sixth step, the quotient 5 divided by 2, 2 quotient remainder is 1. The seventh step, the quotient 2 divided by 2, provided 1 remainder is 0. The eighth step, the quotient 1 divided by 2, provided 0 remainder of 1. The ninth step, readings, because the last one is divided by two before they get after many, so it is the highest readings from the last word read remainder forward, namely 10101000 ② fractional part of the method: Take 2 rounding method, upcoming fractional part multiplied by 2, then take the integer part, fractional part of the rest continue multiplied by 2, then take the integer part, fractional part and the rest is multiplied by 2, has been taken to the fractional part is zero. If you can never be zero, with rounding decimal numbers, like how many decimal places as required when reservations, it is based on the back of a 0 or 1, choice, if it is zero, give it, if it is 1, to the one. In other words 0 and rounding up 1. Integer read from the front of the reading back of the integer, the following Examples: Example 1: 0.125 in terms of the results obtained as binary: the binary converted to 0.125 (0.001) 2 analysis: a first step of 0.125 is multiplied by 2 to give 0.25 , 0 is the integer part, the fractional part of 0.25; a second step, the fractional part 0.25 is multiplied by 2 to give 0.5, 0 is the integer part, the fractional part is 0.5; the third step, the fractional part of 0.5 is multiplied by 2, at 1.0, 1 is the integer part, the fractional part is 0.0; the fourth step, reading from the first read, read the last one, namely 0.001. Example 2, 0.45 converted to binary (reserved to four decimal places) we can see from the above step, when the fifth multiply when the result is 0. 4, then the fractional part of the continuing multiplied by 2, multiplied by 2 and get 0.8,0.8 to 1.6 this has been multiply it and eventually impossible to get the fractional part is zero, therefore, had to learn this method when rounding decimal, but only two binary 0 and 1, so it was 0 and rounding up 1. The computer will also generate an error in the translation, but because a lot of reservations digits, high precision, it can be ignored. So, we can conclude that the result will be equal to about 0.45 0.0111 converted to a binary method described above is converted to a decimal to binary approach requires attention are: 1) convert decimal to binary, requires divided into two integer and fractional parts respectively, conversion 2) when the integer conversion, using modulo 2 method, and when the fractional conversion, is multiplied by 2 with rounding method 3) Note that the direction of their reading Thus, from the above method, we can conclude that in addition to the decimal number 168.125 converted into binary 10101000.001, or decimal numbers into binary numbers approximately equal 10,101,000.0111. (2) regardless of the binary to decimal integer and fractional part of the method: add the weights by the method, ie right in the binary number is multiplied by each, and then the sum that is a decimal number. Example binary number is converted to decimal number 101.101. calculation process: 0111. (2) regardless of the binary to decimal integer and fractional part of the method: add the weights by the method, ie right in the binary number is multiplied by each, and then the sum that is a decimal number. Example binary number is converted to decimal number 101.101. calculation process: 0111. (2) regardless of the binary to decimal integer and fractional part of the method: add the weights by the method, ie right in the binary number is multiplied by each, and then the sum that is a decimal number. Example binary number is converted to decimal number 101.101. calculation process:

(1*2+0*2+1*2).(1*2+0*2+1*2)=5.625

The outcome: (101.101) 2 = (5.625) 10 we are doing binary conversion to decimal Note 1) to know each binary weights 2) to be able to find each value 

From the beginning of last count, followed by 0,1,2 ... as the first bit (bit 0 Note that from the beginning of the number, rather than 1)

Bit n number (0 or 1) is multiplied by 2 ^ n

The result of the addition is the answer

 

 

Published 49 original articles · won praise 7 · views 30000 +

Guess you like

Origin blog.csdn.net/qq_29680975/article/details/103507907