Today, let's talk about: "What is binary"

Source: Internet
Author: User

First, remember not to ask why:"In a computer, all data is expressed in binary."


For example, whether your computer is a 32-bit system or a 64-bit system. In fact, it is about the computing and storage capabilities of your computer. It can compute and store up to 32 power data or up to 64 power data of 2. When I see 32 or 64, some people may say, How do computers compute and store such data? Slow down. Let me calculate the power of 2 to the power of 32 or the power of 64.


--------------------------------------

To the power of 0

To the power of 1 (1st fingers)

To the power of 2 (2nd fingers) [2 to the power of 2 to four]

To the power of 3 (3rd fingers) [3 to the power of 8, this ...]

4 to the power of (4th fingers) [4 to the power of 4 to 16]

32: 5 to the power of 2 (5th fingers) [5 (Power) equals 3 + 2 in 32]

64: power 6 of 2 (6th fingers) [power 6) corresponds to 64]

7 to the power of (7th fingers) [7 to the power) and 1 sound are very similar]

256: The power of 2 (8th fingers) [8 (power) and 2, 10 points perfect]

512: 9 to the power of 2 (9th fingers) [9 to the power of 5 statue]

1024:2 to the power of 10 (10th fingers) [10 (to the power) corresponds to 1024]

From the power of 2 to the power of 10, even if you can't blurt out, at least you have to do it.Only a handful.

--------------------------------------

2048: 2's 11th power

4096: 2's 12 Power

8192: power 13 of 2

16385: The 14th power of 2

32768: The 15th power of 2

65536: power 16 of 2

17th power of 131072: 2

262144: 2's 18th power

524288: power 19 of 2

1048576: power 20 of 2

--------------------------------------

............

............

............


Too much. If you are interested, do it yourself. Let's see if you dare not say that the power of 2 is 32 or 64.




Well, let's get down to the truth and understand the essence of binary.


Take a binary integer for example:

0111. In binary, It is understood as follows: 0x (Power 3 of 2) + 1x (power 2 of 2) + 1x (power 1 of 2) + 1x (0 power of 2) = 0x8 + 1X4 + 1X2 + 1x1 = 7.

----------------------------------------

Explanation: decimal point of the number in the hexadecimal notationFirst on the leftStartCalculate to the left, Respectively multiplied by the 0 power of the base system-> multiplied by the 1 power of the base system-> multiplied by the 2 power of the base system-> multiplied by the 3 power of the base system...


Take another decimal point of the binary:

0.0111. In binary, It is understood as follows: 0x (power-1 of 2) + 1x (power-2 of 2) + 1x (power-3 of 2) + 1x (2 to the power of 4) = 0x (1/2) + 1x (1/4) + 1x (1/8) + 1x (1/16) = calculate it by yourself.

----------------------------------------

Explanation: decimal point of the number in the hexadecimal notationFirst on the rightStartCalculate to the right, Respectively multiplied by the-1 power of the base system-> multiplied by the-2 power of the base system-> multiplied by the-3 power of the base system-> multiplied by the-4 power of the base system...

Digress: Do not tell me that I do not understand "negative power "! Negative power: the reciprocal of the positive power of a number, that is, the negative power.




Therefore, it is very easy to convert the binary number into decimal.

You only need to write the binary number to the left and right of the decimal point.Expansion of weighting coefficientAnd then sum the values according to the decimal addition Rules. This is called"Add by weight.


Example:

Binary:

0111.0111 = 0x (Power 3 of 2) + 1x (power 2) + 1x (power 1 of 2) + 1x (power 0 of 2) + 0x (power-1 of 2) + 1x (power-2 of 2) + 1x (power-3 of 2) + 1x (power-4 of 2) = 0x8 + 1X4 + 1X2 + 1x1 + 0x (1/2) + 1x (1/4) + 1x (1/8) + 1x (1/16) = You can calculate it yourself.




In turn, how can we convert the decimal number into a binary number?


Before talking about this, let's look at an example:


Decimal integerA, Convert to binary numberDcbaIn the form"Add by weight"Method, get:

A = A x (0 power of 2) + B x (1 power of 2) + C X (2 power) + d x (3 power of 2)


Both sides of the equation,Divide by 2 at the same time, Get:

A/2 = A x (0 power of 2)/2 + B x (1 power of 2)/2 + C X (2 power of 2) /2 + D x (3 power of 2)/2

On the right side of the equation above, because only a is multiplied by the 0 power of 2, it is divisible by 2;

So the first time divided by 2, the remainder is obtained, that is, the first A to the left of the decimal point of its binary;


On the Right of the equation above, obtain,Vendors:B x (0 power of 2) + C x (1 power of 2) + d x (2 power)Divide the second time by 2, Get:

B x (0 power of 2)/2 + C x (1 power of 2)/2 + D x (2 power)/2

In the formula above, because only B is multiplied by the 0 power of 2, it is divisible by 2;

So the second time divided by 2, the remainder is obtained, that is, the second digit B on the left of the decimal point of its binary;


......

And so on,Divide by 2 and take the remainder,The service provider is divided by 2 and then the remainder is obtained., The decimal place on the left of the binary will be continuously obtained ...... Bit ABCD.




Let's look at another example:


Decimal decimalB, Convert to binary number0. efghIn the form"Add by weight"Method, get:

B = e x (power-1 of 2) + f x (power-2 of 2) + G x (power-3 of 2) + H x (Power 4 of 2)


Both sides of the equation,Multiply by 2 at the same time, Get:

Bx2 = e x (2-1 Power) x2 + f x (2-2 power) x2 + G x (2-3 power) x2 + H x (2-4 Power) x2

On the right side of the equation above, because only E is multiplied by the-1 power of 2, it is multiplied by 2 to become an integer;

So the first time multiplied by 2, an integer is obtained, that is, the first digit e on the right of the decimal point of its binary;


On the Right of the equation above, extract e,The remaining decimal part:F x (power-1 of 2) + G x (power-2 of 2) + H x (power-3 of 2)The second time multiplied by 2, Get:

F x (power-1 of 2) x2 + G x (power-2 of 2) x2 + H x (power-3 of 2) x2

In the above formula, because f is only multiplied by the power of-1 of 2, it is multiplied by 2 to become an integer;

So the second time multiplied by 2, an integer is obtained, that is, the second digit F to the right of its binary;


......

And so on,Multiply by 2 to take the integer part,Multiply the remaining decimal part by 2 and then take the integer part., The decimal place on the right of the binary will be continuously obtained ...... Bit efgh.

Today, let's talk about: "What is binary"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.