Introduction to Storing numbers and text
In this module we will discuss how a computer stores the numbers and text that your programs work with.
After completing the module you will have the skills and knowledge necessary to:
- Explain how numbers are stored in binary and hexadecimal form
- Convert numbers between binary and decimal form
- Convert numbers between binary and hexadecimal form
- Explain how signed integers are stored in two's complement form
- Convert signed integers between decimal and two's complement form
- Explain how real numbers are stored as floating-point form
- Explain how characters are stored using ASCII and Unicode
In the next lesson we will examine how a computer stores non-negative integers such as 0, 23, and 318.
Computer Science: A Structured Programming Approach Using C
Question: How does a computer store numbers and text?
An early convention for representing text was ASCII - the American Standard Code for Information Interchange - which assigned the characters on a standard typewriter to a number that could be stored in 7-bits (i.e. between 0-127).
Capital 'A' is 65, capital 'B' is 66, lowercase 'a' is 97, lowercase 'b' is 98, etc.
This system works great for storing English text, but it doesn't include the accented characters that are needed in other European languages, and it definitely doesn't include the thousands of characters or symbols found in Chinese,
Korean, and many other languages. For that purpose, Unicode was created as a much larger character set in the late 1980s, although it still includes as a very small subset those original 127 characters from ASCII. So a capital 'A' is still
essentially represented as the number 97, just as it has been for over 50 years.
In a more technical sense, computers don't really store numbers either. They are really just a collection of billions of transistors that are either at a high or low voltage, and we group these transistors into groups of 8, 16, 32, 64,
or more bits and think of them as a binary number that is composed of that many bits. This allows numbers that are essentially infinitely large, which is why computers can store any length of text, or strings of colors
(pictures and videos), or strings of audio frequency (music), etc.