C Language Blog (4) How does the programming base understand binary thinking and data storage?

Source: Internet
Author: User

The basics of programming that I'm going to describe are how to understand binary thinking and the storage of data, which is the programming foundation that many beginners need.

We usually use the numbers are composed of 10 0~9 total, such as 1, 9, 10, 297, 952, and so on, a number can represent a maximum of nine, if you want to represent 11 or 11, 29, 100, and so on, you need multiple numbers together.

For example, the result of 5+8, a number is not enough, can only "carry", with 13来, then "into a" equivalent to 10, "into two" equivalent to 20.

Because every ten into one, also because only 0~9 a total of 10 numbers, so called decimal (decimalism).

The binary is the rounding system. In the addition (subtraction) operation, the X-input (borrowing) one is the X-system, which also contains an X number, the base is X. Decimal has 0~9 a total of 10 numbers, the base is 10, in addition and subtraction operation, every ten into one, borrow one when ten.

We might as well expand our thinking, since we can use 0~9 a total of 10 numbers to represent the value, then you can also use 0, 12 numbers to represent the value, this is binary (binary).

Binary thinking

Binary is only 0 and 12 digits, the cardinality is 2, in addition and subtraction operation, every two in one, borrow one when two.

    • Represents values: 0, 1, 10, 111, 100, 1000001
    • Additions: 1+0=1, 1+1=10, 10+110=1000, 111+111=1110,
    • Subtraction: 1-0=1, 10-1=1, 100-11=1, 1010-101=101

The correspondence between decimal and binary binary
Binary 0 1 10 11 100 101 110 111 1000 1001 1010 1011 1100 1101 1110 1111
Decimal 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

Binary and Decimal conversions:
    • Decimal 4321 = 4x103 + 3x102 + 2x101 + 1x100
    • Binary 1101 = 1x23 + 1x22 + 0x21 + 1x20 = 8 + 4 + 0 + 1 = 13
    • Binary 110.11 = 1x22 + 1x21 + 0x20 + 1x2-1 + 1x2-2 = 4 + 2 + 0 + 0.5 + 0.25 = 6.75

If you want to learn more about binary addition and subtraction operations, we've provided two.

This is the choice of learning content, you can completely skip, will not affect the back of the study.

1) binary addition: 0001 + 0001 = 0010

Figure 1: binary addition

2) binary subtraction: 0010-0001 = 0001

Figure 2: Binary subtraction

In memory, the data is stored in binary form.

Storage of in-memory data

The information that the computer wants to process is various, such as decimal number, text, symbol, graphic, audio, video, etc., this information is different in people's eyes. But for computers, they are all the same in memory and are represented in binary form.

To learn programming, you must understand the binary, which is the basis of computer processing data.

The memory strip is a very sophisticated component that contains hundreds of millions of electronic components that are small and reach the nanometer level. These components, in fact, are the circuit, the voltage of the circuit will change, either 0V, or 5V, only these two voltages. 5V is the power, with one means, 0V is a power outage, expressed by the said. So, there are 2 states of a component, 0 or 1.

We use circuits to control the power-off of these components and get a lot of combinations of 0 and 1. For example, 8 components have 28 = 256 different combinations, 16 components have 216 = 65536 different combinations. Although a component can only represent 2 values, many of these values are represented by multiple combinations.

We can give each combination a specific meaning, for example, can be used 1101000, 00011100, 11111111, 00000000, 01010101, 10101010来 to denote C, language, speech, medium, text, nets these words, then combine 1101000 00011100 11111111 00000000 01010101 10101010 means "C language Chinese net".

In general, we do not use a single component, but the 8 components as a unit, even if it represents a small number, such as 1, also requires 8, that is, 00000001.

1 components are called 1-bit (bit) or 1-bit, 8 components are called 1 bytes (byte), then 16 components are 2byte,32 4Byte, and so on:

    • 8x1024 a component is 1024Byte, abbreviated to 1KB;
    • 8x1024x1024 a component is 1024KB, abbreviated to 1MB;
    • 8x1024x1024x1024 a component is 1024MB, abbreviated to 1GB.

Now, you know how many components are in 1GB of memory. We usually say the size of the file is how many kb, how many MB, that is the meaning.

Unit conversions:

    • 8 Bit = 1Byte
    • 1024Byte = 1KB
    • 1024KB = 1MB
    • 1024MB = 1GB
    • 1024GB = 1TB

So in memory there are no ABC characters, and no gif, jpg such as pictures, only 0 and 12 numbers, the computer also only know 0 and 1. So, the computer uses binary instead of the familiar decimal, the data written in memory will be converted to a combination of 0 and 1.

I hope you will support this blog to write the basics of programming.

Transferred from: http://c.biancheng.net/cpp/html/2839.html

C Language Blog (4) How does the programming base understand binary thinking and data storage?

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.