Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the storage range of an byte in a computer?

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "how much is the storage range of a byte in the computer". In the daily operation, I believe that many people have doubts about the storage range of a byte in the computer. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the question of "how much is the storage range of a byte in the computer?" Next, please follow the editor to study!

We know that for signed types, the computer will treat the highest bit as a symbolic bit, 0 for positive and 1 for negative. For example (the following examples are for 8-bit signed numbers):

0000 0001 is 1p1000 0001 that is-1, so it is easy to get that the range of 8-bit signed values should be 1111 1111-0111 1111, that is,-12700127. The question is, where did-128come from?

Before we explain this problem, let's add some additional knowledge:

In the storage and calculation of the computer, the complement is used for processing and operation. before we figure out the benefits of using the complement, we need to clarify the following three concepts:

Source code: a binary point representation of a number in a computer. The original code representation adds a symbol bit (that is, the highest bit is the symbol bit) before the value: the positive bit is 0, the negative bit is 1 (0 has two representations: + 0 and-0), and the remaining bits represent the size of the value.

Inverse code: the inverse code of a positive number is the same as its original code; the inverse code of a negative number is a bit-by-bit inversion of its original code, except for symbol bits.

Complement: the complement of a positive number is the same as its original code; the complement of a negative number is equal to its inverse code + 1.

Obviously, the example at the beginning of the article is the original code, which is very consistent with our intuitive feeling, but there is trouble in the calculation, if the direct operation, such as 1 + (- 1) = 0, 0000 0001 + 1000 0001 = 1000 0010 (- 2), it is obviously wrong, so symbol bits and numerical bits must be dealt with separately! This will increase the hardware cost of the computer. Let's try the complement instead. The source code of 1 is 0000 0001, the inverse code is 0000 0001, the complement code is 0000 0001 (positive numbers are the same), and the original code of-1 is 1000 0001, the inverse code is 1111 1110, and the complement code 11111111 (11111110 + 00000001). So 1 + (- 1) uses the complement to calculate 00000001 + 111111111 = 00000000 (the highest bit overflow discard), and the result is correct.

Thus it can be seen that the subtraction operation can be transformed into an addition operation, and the computer only needs to realize the addition circuit, and the conversion process from the source code to the complement code and from the complement code to the original code is completely the same, why? It can be proved simply as follows:

Suppose a 32-bit machine, X is a negative number (the highest bit is a symbol bit, for a negative number, that is, 1), then there is X (absolute value) + X (inverse) = 0xFFFFFFFFF, so X (absolute value) + X (inverse) + 1 × FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF

1) then for A, B > 0, if K is a negative number, then the subtraction operation will be transformed into an addition operation if there is Amurmurb A + (0murk (absolute value)) = Aquik (complement).

2) X (absolute value) = 0murX (complement); both sides multiply by-1 to get-X (absolute value) =-0-(- X (complement)) = 0-(X (complement (absolute value) = X (complement) (anti) + 1min X (absolute value) is the original code X. therefore, the above formula shows that the complement of the original code X equals X is added by one, that is to say, the complement of the X complement is the original code. Whether it is the original code or complement code, the way of finding the original code is completely the same.

Going back to the initial question, why is the minimum value of an 8-bit signed value-128 instead of-127? let's list a comparison table of some source, inverse and complement codes:

We can see from the above table that 0 can be expressed in both the source code and the inverse code, while the corresponding complement has only one representation.-128 cannot be expressed in the source code and the inverse code, but can be expressed in the complement (1000 0001 minus 1 of the complement of-127gets 1000 0000). The values in the computer are stored and calculated in the form of complement, of course-128 can be expressed, so the range of 8-bit signed values is-128-127, and so can other digits (16, 32, 64).

To put it bluntly, the source code of-0 and + 0 is 1000 0000 and 0000 0000 these two are repeated, but-0 do not waste the same as the complement, let it say-128is OK.

At this point, the study on "how much is the storage range of an byte in the computer" 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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report