Главная Обратная связь

Дисциплины:






Read and translate the text. A set of 256 patterns is large enough to have a different pattern for each letter of the alphabet, the digits



Character Data

A set of 256 patterns is large enough to have a different pattern for each letter of the alphabet, the digits, punctuation characters, and a whole variety of special characters. If a program has to work with textual data, composed of lots of individual characters, then each character can be encoded in a single byte. Of course there have to be conventions that assign a specific pattern to each different character. At one time, different computer manufacturers specified their own character encoding schemes. Now, most use a standard character encoding scheme known as ASCII (for American Standard Code for Information Interchange). Although standardized, the assignments of patterns to characters is essentially Arbitrary.

This ASCII scheme is mandated by an international standard. It specifies the bit patterns that should be used to encode 128 different characters including all the letters of the Roman alphabet, digits, punctuation marks and a few special control characters like "Tab". The remaining 128 possible patterns are not assigned in the standard. Some computer systems may have these patterns assigned to additional characters like ™, ±, . Bit patterns can also be used to represent numbers. Computers work with integer numbers and "floating point" numbers. Floating point numbers are used to approximate the real numbers of mathematics.

A single byte can only be used to encode 256 different values. Obviously, arithmetic calculations are going to work with wider ranges – like -2,000,000,000 to +2,000,000,000. Many more bits are needed to represent all those different possible values. All integer values are represent using several bytes. Commonly, CPUs are designed to work efficiently with both two-byte integers and four-byte integers (the CPU will have two slightly different versions of each of the arithmetic instructions). Two-byte integers are sufficient if a program is working with numbers in the range from about minus thirty thousand to plus thirty thousand; the four-byte integers cover the range from minus to plus two thousand million.

The number representations have an obvious regular pattern. Unlike the case of character data, the patterns used to represent integers can not be arbitrary. They have to follow regular patterns in order to make it practical to design electronic circuitry that can combine patterns and achieve effects equivalent to arithmetic operations. The code scheme that provides the rules for representing numbers is known as "two's complement notation"; this scheme is covered in introductory courses on computer hardware.



There are other coding schemes for integers but "two's complement notation" is the most commonly used. The actual coding scheme used to represent integers, and the resulting bit patterns, is not often of interest to programmers. While a computer requires special bit patterns representations of numbers, strings of 0 and 1 characters are not appropriate for either output or input. Humans require numbers as sequences of digit characters. Every time a number is input to a program, or is printed by a program, some code has to be executed to translate between the binary computer representation and the digit string representation used by humans.

The electronic circuits in the CPU can process the binary patterns and correctly reproduce the effects of arithmetic operations. There is just one catch with integers – in the computer they are limited to fixed ranges. Two-bytes are sufficient to represent numbers from -32767 to +32768 – and it is an error if a program generates a value outside this range. Mistakes are possible. Consider for example a program that is specified as only having to work with values in the range 0 to 25000; a programmer might reasonably choose to use twobyte integers to represent such values. However, a calculation like "work out 85% of 24760" could cause problems, even though the result (21046) is in range. If the calculation is done by multiplying 85 and 24760, the intermediate result 2104600 is out of range.

Arithmetic operations that involve unrepresentable (out of range) numbers can be detected by the hardware – i.e. the circuits in the ALU. Such operations leave incorrect bit patterns in the result, but provide a warning by setting an "overflow" bit in the CPU's flags register. Commonly, computer systems are organized so that setting of the overflow bit will result in the operating system stopping the program with the error. The operating system will provide some error message. (The most common cause of "overflow" is division by zero – usually the result of a careless programming error or, sometimes, due to incorrect data entry.)





sdamzavas.net - 2020 год. Все права принадлежат их авторам! В случае нарушение авторского права, обращайтесь по форме обратной связи...