In the previous chapter, we learned how numbers are represented using different number systems, and how binary in particular forms the true internal language of computer hardware. However, plain positive whole numbers are only part of the story. Real programs need to work with negative numbers, decimal values with fractional parts, and even text made up of letters, punctuation, and symbols, none of which fit neatly into the simple binary representation we covered earlier.
Data representation in Computer Organization deals with exactly this problem: how a computer, which can only physically store patterns of 0s and 1s, manages to represent all of these different kinds of information accurately and consistently. Every negative number, every decimal fraction, and every letter you type on a keyboard is ultimately converted into a specific binary pattern following well-defined rules, and understanding these rules is essential to understanding how computers handle data at the lowest level.
In this tutorial, you will learn how computers represent signed numbers using sign-magnitude, 1's complement, and 2's complement methods, how characters are represented using coding schemes like ASCII, and how floating-point numbers allow computers to work with decimal values.
Plain binary, as covered in the previous chapter, works well for representing positive whole numbers, but it has no built-in way of expressing a negative value. Since a computer only stores 0s and 1s, there is no natural minus sign available the way there is on paper. To solve this, computer systems reserve part of a binary number specifically to indicate whether the value is positive or negative.
Several different approaches have been developed over time to represent signed numbers in binary, and understanding each one helps explain why modern computers settled on the particular method they use today.
Sign-magnitude representation is the simplest and most intuitive approach. The leftmost bit of a binary number, known as the most significant bit, is reserved purely to indicate the sign of the number: 0 for positive, and 1 for negative. The remaining bits represent the actual magnitude, or absolute value, of the number.
Represent +9 and -9 using 8-bit sign-magnitude form +9 in binary magnitude: 00001001 Sign bit for positive: 0 Final representation: 00001001 -9 in binary magnitude: 00001001 Sign bit for negative: 1 Final representation: 10001001
While sign-magnitude is easy to understand, it has a notable drawback: it results in two different representations for zero, one for positive zero and one for negative zero, which complicates circuit design and arithmetic operations. This limitation led to the development of complement-based methods.
In 1's complement representation, a negative number is formed by simply inverting every bit of its positive binary equivalent, flipping every 0 to a 1 and every 1 to a 0. Positive numbers are represented exactly the same way as in ordinary binary.
Represent -12 using 8-bit 1's complement +12 in binary: 00001100 Invert every bit: 11110011 Final representation: 11110011 (this represents -12)
1's complement solves some of the issues of sign-magnitude, but it still suffers from having two representations of zero, one being all 0s and the other being all 1s. This remaining inefficiency is what eventually led to the widespread adoption of 2's complement.
2's complement is the method actually used by virtually all modern computers to represent signed integers. It is formed by taking the 1's complement of a number and then adding 1 to the result. This small extra step eliminates the dual representation of zero and simplifies binary arithmetic significantly.
Represent -12 using 8-bit 2's complement +12 in binary: 00001100 Invert every bit (1's complement): 11110011 Add 1: 11110100 Final representation: 11110100 (this represents -12)
The biggest advantage of 2's complement is that addition and subtraction can be performed using the exact same binary addition circuitry, regardless of whether the numbers involved are positive or negative. This is a major reason why 2's complement became the standard choice in real computer hardware.
Calculate 15 - 9 using 8-bit 2's complement addition 15 in binary: 00001111 9 in binary: 00001001 2's complement of 9: 11110111 Add 15 and the 2's complement of 9: 00001111 + 11110111 ----------- 00000110 (carry out is discarded) Result: 00000110 = 6 (which matches 15 - 9)
Notice how subtraction was carried out entirely using addition, simply by adding the 2's complement of the number being subtracted. This trick is exactly why 2's complement is so valuable for hardware design.
| Representation | How Negative Numbers Are Formed | Representations of Zero |
|---|---|---|
| Sign-Magnitude | Set the leftmost bit to 1, keep the rest as magnitude | Two (positive zero and negative zero) |
| 1's Complement | Invert every bit of the positive value | Two (all 0s and all 1s) |
| 2's Complement | Invert every bit, then add 1 | One (only all 0s) |
Beyond numbers, computers also need a consistent way to represent text, since every letter, digit, punctuation mark, and symbol typed on a keyboard must eventually be stored as binary data. ASCII, short for American Standard Code for Information Interchange, is one of the earliest and most widely recognized character encoding schemes used for this purpose.
ASCII assigns a unique numeric value, ranging from 0 to 127, to each character, which can then be represented using 7 bits of binary data. This includes uppercase and lowercase letters, digits, punctuation marks, and several special control characters used for formatting and communication.
Character: C ASCII decimal value: 67 Binary representation (7-bit): 1000011 Character: S ASCII decimal value: 83 Binary representation (7-bit): 1010011
So when the word "CS" is typed and stored by a computer, it is not stored as the letters themselves in any direct sense, but rather as the binary patterns 1000011 followed by 1010011, based entirely on their assigned ASCII values.
While ASCII was extremely influential and is still widely used today, it can only represent 128 different characters, which is not enough to cover characters from many of the world's languages. This limitation eventually led to the development of more extensive encoding systems like Unicode, which can represent a vastly larger range of characters from virtually every writing system in use today.
So far, every example we have looked at has dealt with whole numbers. But real-world data frequently involves decimal values with fractional parts, such as an average watch time of 4.75 minutes per video. Floating-point representation is the method computers use to store and work with these kinds of decimal numbers in binary form.
A floating-point number is generally broken down into three parts: a sign bit indicating whether the number is positive or negative, an exponent that determines the scale or magnitude of the number, and a mantissa, also called the significand, which holds the actual significant digits of the value. This structure is conceptually similar to scientific notation, where a number is expressed as a value multiplied by a power of a base.
Decimal value: 12.5 Written in binary scientific notation: 12.5 = 1100.1 (binary) 1100.1 = 1.1001 × 2^3 Floating-point breakdown: Sign: 0 (positive) Exponent: 3 (adjusted using a bias in real systems) Mantissa: 1001
This example simplifies the actual process used by real computer systems, which follow a precise standard known as IEEE 754 to determine exactly how many bits are allocated to the sign, exponent, and mantissa, along with how the exponent's bias is calculated. Even so, the core idea remains the same: breaking a decimal value into a sign, a scale, and a set of significant digits, much like scientific notation does on paper.
Every operation a computer performs, whether it is calculating a channel's average watch time, comparing two subscriber counts, or displaying a comment typed by a viewer, ultimately depends on these underlying representation rules being applied consistently. If a computer's hardware and software did not agree on exactly how numbers and characters are encoded, even simple operations like addition or displaying text correctly would become unreliable.
This is precisely why data representation standards, from 2's complement for integers to IEEE 754 for floating-point values and ASCII or Unicode for text, are so tightly defined and consistently followed across virtually all modern computer systems.
| Advantages | Limitations |
|---|---|
| 2's complement allows addition and subtraction to use the same hardware circuitry. | Floating-point representation can introduce small rounding errors for certain decimal values. |
| ASCII provides a simple, widely supported way to represent common English text characters. | ASCII cannot represent characters from many non-English writing systems on its own. |
| Standardized representation rules ensure consistent behavior across different computer systems. | Understanding the exact bit-level rules can feel complex for beginners at first. |
| Mistake | Correct Practice |
|---|---|
| Confusing 1's complement with 2's complement. | Remember that 2's complement always adds 1 after inverting the bits, while 1's complement stops at inverting alone. |
| Assuming sign-magnitude and 2's complement represent negative numbers the same way. | Remember that sign-magnitude only flips the sign bit, while 2's complement transforms the entire bit pattern. |
| Thinking ASCII can represent every character from every language. | Remember that ASCII is limited to 128 characters, and systems like Unicode were built to cover a much wider range. |
| Assuming floating-point numbers are always represented with perfect precision. | Understand that floating-point representation can introduce small rounding errors for certain decimal values. |
Data representation explains how a computer, capable of storing only patterns of 0s and 1s, manages to represent negative numbers, text characters, and decimal values accurately and consistently. Signed number representation methods like sign-magnitude, 1's complement, and 2's complement each solve the problem of representing negative values in different ways, with 2's complement ultimately becoming the standard due to its efficiency in hardware design.
Character encoding schemes like ASCII allow letters, digits, and symbols to be represented as binary data, while floating-point representation extends binary further to handle decimal values using a structure built from a sign, an exponent, and a mantissa. Together, these rules form the backbone of how every kind of data, from a simple counted number to a full sentence of text, is ultimately stored and processed inside a computer.
With data representation covered, you are now ready to explore Boolean algebra, where the logical operations that drive every computation happening inside a computer's circuits are formally introduced and explained.