In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "what is the way of data storage in C language". In daily operation, I believe that many people have doubts about what the way of data storage in C language is. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the question of "what is the way of data storage in C language?" Next, please follow the editor to study!
I. Source code
The original code of a number (the original binary code) has the following characteristics:
The highest bit is the symbol bit, with 0 for positive and 1 for negative
The rest of the numerical value is the binary number of the absolute value of the numerical value itself.
The source code of a negative number is based on its absolute value, and the highest bit becomes 1.
The following values are described in 1 byte size:
Decimal number
Original code
+ 15
0000 1111
-15
1000 1111
+ 0
0000 0000
-0
1000 0000
Note: the representation of the original code is easy to understand, and it is convenient to convert with the signed number itself, as long as the symbol is restored, but when two positive numbers are subtracted or different symbolic numbers are added, it is necessary to compare which absolute value of the two numbers is larger in order to determine which one is positive or negative, so the original code is not convenient for addition and subtraction.
Second, inverse code
For positive numbers, the inverse code is the same as the original code
For negative numbers, the symbol bits remain unchanged, while the other parts are reversed (1 to 0, 0 to 1)
Decimal number
Inverse code
+ 15
0000 1111
-15
1111 0000
+ 0
0000 0000
-0
1111 1111
Note: inverse code operation is also inconvenient and is usually used as an intermediate transition for complementary codes.
Third, complement code
1. Complement description
In a computer system, values are always stored in complements.
Features of complement:
For positive numbers, the original code, inverse code and complement are the same.
For a negative number, its complement is added by its inverse code.
The complement symbol bit does not move, the other bits are inverted, and finally the whole number is added by 1 to get the original code.
Decimal number
Complement code
+ 15
0000 1111
-15
1111 0001
+ 0
0000 0000
-0
0000 0000
2. The meaning of complement
In computer systems, values are always stored in complements, mainly for the following reasons:
Unify the zero coding
Unify symbol bits with other bits
Transform subtraction into addition
When two numbers represented by complement are added together, if the highest bit (symbol bit) has carry, the carry is discarded.
Example: use 8-bit binary numbers to represent + 0 and-0, respectively
Decimal number
Original code
+ 0
0000 0000
-0
1000 0000
Decimal number
Inverse code
+ 0
0000 0000
-0
1111 1111
Note: no matter it is stored in the original code or in the inverse code, 0 also has two forms of representation. But if it is stored as a complement, the complement unifies the zero code:
Decimal number
Complement code
+ 0
0000 0000
-0
10000 0000 because only 8 bits are used, the highest bit 1 is discarded and becomes 0000 0000
IV. Case demonstration
Analog computer operation
1) 76-32
Computer algorithm: 76 + (- 32)
2) 76
Source code: 0100 1100
Inverse code: 0100 1100
Complement: 0100 1100
3)-32
Source code: 1010 0000
Inverse code: 1101 1111
Complement: 1110 0000
4) add
1110 0000
0100 1100
5) check calculation
Results: 1 0010 1100
Discard complement: 0010 1100
Result complement: 0010 1100
Inverse code: 0010 1100
Conversion source code: 0010 1100
Note: since the discard complement 0 is positive, the conversion source code is the same as the complement code.
6) results: 44
Note:
1. Positive number of symbol bits: 0
2. Negative number of symbol bits: 1
3. The result of complement calculation. If the symbol bit exceeds the size limit, the symbol bit will be omitted.
4. Complement result: the opening number is 1, it is converted to the source code according to the negative rule, and the first 0 is a positive conversion.
5. Positive numbers: source code, inverse code, complement code, same
6. Negative source code conversion code: the symbol remains unchanged, other bits 0 become 1, 1 become 0
7. Negative inverse code transcoding: add 1 to the result of the inverse code
8. The result of addition or subtraction cannot be greater than or less than negative 127.
At this point, the study of "what is the way to store data in C language" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.