π Lecture 01 β An Overview & Number Systems
π Overview: This foundational lecture introduces the fundamental difference between analogue and digital quantities, explains the rationale for digital processing, and establishes the binary number system as the core of digital logic design. It covers the basic building blocks of digital systemsβlogic gates, combinational and sequential circuitsβand culminates in a formal treatment of number systems, including decimal, binary, and a hypothetical base-5 system, to illustrate how any radix can represent values using positional notation.
ποΈ Topics Covered
The lecture begins by contrasting analogue and digital quantities, illustrating how digital systems use discrete samples to represent continuous signals. It then explains the electronic processing of these signals, introducing the binary number system as the foundation of digital values. The advantages of the digital domain are enumerated, followed by an overview of digital components including logic gates, combinational circuits, sequential circuits, programmable logic devices (PLDs), memory, and A/D-D/A converters. The lecture concludes with a detailed analysis of number systems, using the decimal and a hypothetical caveman base-5 system to explain the binary number system and the representation of integer and fractional values through positional weights.
π Lecture Summary
Analogue versus Digital
Most measurable quantities in nature, such as the intensity of light during the day, the rise and fall in temperature over a 24-hour period, and the velocity of a car, are continuous. These values change gradually over a range with a minimum and maximum. In contrast, digital quantities are not continuous but represent values measured at discrete intervals. A continuous signal can be sampled at fixed, equal intervals to produce a set of discrete values (e.g., 15 samples like 1, 2, 4, 7, 18, 34, etc.). The reconstructed signal from these samples only approximates the original; under-sampling (e.g., using only 7 samples) causes missing peaks and dips. A more accurate representation requires increasing the number of samples.
π‘ Why this matters: The accuracy of a digital representation of the real world depends directly on the rate at which the continuous signal is sampled.
Electronic Processing of Continuous and Digital Quantities
Continuous quantities or their digital representations must be converted into voltages for electronic processing. There are two fundamental types of systems: Analogue Electronic Systems accept and process continuous signals converted by transducers into continuous voltage/current signals. Digital Electronic Systems process discrete samples. Digital systems do not represent discrete samples as unique voltage values (e.g., 39 mV for the number 39) because large numbers would require impractically high voltages. Instead, they use two voltage values: +5 volts (logic high/logic 1) and 0 volts (logic low/logic 0). The Binary Number System is used to represent more than two values by combining these binary digits (bits).
Digital Systems and Digital Values
Digital systems are designed to work with two voltage states, which can represent binary values like β0β/β1β, βonβ/βoffβ, or βhotβ/βcoldβ. To represent a wider range of values, digital systems use the Binary Number System, which is based on two values (0 and 1). A single bit can represent only two values, but by combining bits, any quantity can be represented. For example, a palette of four colours can be represented by combinations of two bits (00, 01, 10, 11), and a temperature of 39Β°C is represented digitally as the binary number 100111. The number of digits used is proportional to the range of values to be represented. The binary number 100111 is stored electronically as +5v, 0v, 0v, +5v, +5v, +5v.
Advantages of working in the Digital Domain
Handling information digitally offers several advantages: Storing and processing data is more efficient (e.g., a CD stores vast amounts of data vs. analogue tapes). Transmission of data is more reliable, as it is less prone to errors, and errors are easier to detect and correct. Data can be easily and precisely reproduced, leading to superior digital video and audio quality. Digital systems are easy to design and implement, as the simple two-state circuitry allows for powerful systems. Finally, digital circuits occupy small space, with powerful computers fitting on a small motherboard.
Information Processing by a Digital System
A digital system, such as a computer, can handle all kinds of information, all represented as binary numbers. This includes numbers (integers, fractions), text (using standards like ASCII), drawings and pictures, and music and sound.
Digital Components and their internal working
These specialized circuits are known as Logic Gates, the basic building blocks of any digital circuit. Common gates include the AND gate, OR gate, Inverter (NOT) gate, NOR, NAND, XOR, and XNOR gates. Each performs a unique logical or Boolean operation on input information. These gates are implemented using technologies like CMOS and TTL, which determine operational characteristics.
Combinational Logic Circuits and Functional Devices
A single logic gate is not very useful on its own. When gates are combined to perform a useful operation, such as adding numbers, they form Combinational Logic Circuits. An example is a 1-bit Full-Adder, which adds two binary numbers and produces a Sum and Carry output. Instead of building complex circuits from individual gates, functional devices like Comparators, Decoders, Encoders, Multiplexers, and Demultiplexers are available as Integrated Circuits (ICs).
Sequential logic and implementation
Some digital circuits generate an output based on both the current input and previously saved information. These are Sequential circuits. A digital down-counter, for example, stores a current count value. When it receives an external pulse, it decrements the stored value to produce a new count. Sequential circuits are a combination of combinational circuits and a memory element, called a flip-flop.
Programmable Logic Devices (PLDs)
A modern trend is using configurable hardware that can be programmed by the end user. A PLD for a washing machine controller reduces the need for a large inventory of components and can be easily reprogrammed for design changes, reducing cost and implementation time.
Memory
Memory is critical in digital systems. Read-Only Memory (ROM) stores data permanently and allows only reading. Random Access Memory (RAM) is volatileβdata is lost when power is turned offβand allows both reading and writing.
Analogue to Digital and Digital to Analogue conversion and Interfacing
Because the real world is continuous, two conversions are needed. An Analogue to Digital (A/D) Converter converts an analogue voltage into an equivalent digital representation. A Digital to Analogue (D/A) Converter converts the digital output back to a continuous voltage. This is illustrated by a digitally controlled industrial heater where a temperature sensor's voltage is converted to a digital value, processed, and then converted back to control a heater valve.
Number Systems and Codes
Decimal Number System
The decimal number system has ten unique digits (0-9). It is a positional number system, meaning the position of a digit represents its true magnitude. For example, in 275, the '2' represents 200 and the '7' represents 70. The expression for 275 is:
π Formula: 2 Γ 10Β² + 7 Γ 10ΒΉ + 5 Γ 10β° = 200 + 70 + 5 = 275.
Here, 10 is the base (or radix), and 10Β², 10ΒΉ, 10β° are the weights.
Fractions in Decimal Number System
The integer part is left of the decimal point (weights 10β°, 10ΒΉ, 10Β²...), and the fraction part is right of the decimal point (weights 10β»ΒΉ, 10β»Β², 10β»Β³...).
π Formula: 382.91 = 3 Γ 10Β² + 8 Γ 10ΒΉ + 2 Γ 10β° + 9 Γ 10β»ΒΉ + 1 Γ 10β»Β² = 382.91.
Caveman number system
A hypothetical Base-5 number system with five distinct symbols (β, β, >, β¦, β) representing decimal 0 to 4. This system is used to illustrate that any base can represent numbers.
π Definition β Base (Radix): The number of unique digits (including zero) in a number system.
π Example: The caveman number ββ is equivalent to:
= β Γ 5ΒΉ + β Γ 5β° = (1 Γ 5) + (4 Γ 1) = 9.
π Example: The caveman number ββ¦ββ is:
= (1 Γ 125) + (3 Γ 25) + (4 Γ 5) + (0 Γ 1) = 220.
Binary Number System
Digital systems use the Binary number system, which is a Base-2 number system with only two numbers, 0 and 1. A binary digit (0 or 1) is known as a 'Bit'. Counting in binary is similar to other systems, where a value larger than 1 requires more digits.
Any binary number can be expressed in decimal by using the base value 2 and weights 2β°, 2ΒΉ, 2Β², etc.
π Example: The binary number 10011β (subscript β indicates binary) is:
= (1 Γ 2β΄) + (0 Γ 2Β³) + (0 Γ 2Β²) + (1 Γ 2ΒΉ) + (1 Γ 2β°)
= 16 + 0 + 0 + 2 + 1 = 19.
Fractions in Binary Number System
In a binary number, a decimal point separates the integer and fraction parts. The integer's weights are 2β°, 2ΒΉ, 2Β²..., and the fraction's weights are 2β»ΒΉ, 2β»Β², 2β»Β³...
π Example: The binary number 1011.101β is:
= (1 Γ 2Β³) + (0 Γ 2Β²) + (1 Γ 2ΒΉ) + (1 Γ 2β°) + (1 Γ 2β»ΒΉ) + (0 Γ 2β»Β²) + (1 Γ 2β»Β³)
= 8 + 0 + 2 + 1 + 0.5 + 0 + 0.125 = 11.625.
π‘ Why this matters: While computers handle numbers like 11.625, they use a specialized representation (Floating-Point Numbers) instead of the binary format shown here.
β Key Takeaways
The defining characteristic of digital versus analogue is that digital quantities are discrete, not continuous, and their accuracy depends on the sampling rate. At the hardware level, digital systems are based on a simple two-voltage state system (e.g., +5V and 0V), which represents the binary digits 0 and 1. The binary number system is a base-2 positional number system, and any binary number (integer or fractional) can be converted to its decimal equivalent using an expression of powers of 2. All digital systems, from simple logic gates to complex functional devices, operate on binary numbers, making the binary number system the absolute foundation of the entire field.
π§ Quick Revision Questions
- What is the fundamental difference between an analogue quantity and a digital quantity?
- Why don't digital electronic systems represent discrete sample values as their equivalent voltage values (e.g., 39V for the number 39)?
- Explain the concept of a "positional number system" using the number 275 in decimal as an example.
- Convert the binary integer 11010β to its decimal equivalent.
- Convert the binary fraction 1101.101β to its decimal equivalent.
π Lecture 02 β NUMBER SYSTEMS
π Overview: This lecture covers the fundamental methods for converting between Binary and Decimal number systems, including techniques for both integers and fractions. It also introduces binary arithmetic operations and explains how signed numbers are represented in digital systems using sign-magnitude and 2's complement forms, which are essential for understanding digital logic design.
ποΈ Topics Covered
Binary to Decimal conversion using Sum-of-Weights and Sum-of-non-zero terms methods; Decimal to Binary conversion using Sum-of-Weights and Repeated Division-by-2 for integers, and Sum-of-Weights and Repeated Multiplication-by-2 for fractions; Binary arithmetic operations including addition, subtraction, multiplication (including shift method), and division (including shift method); Signed and unsigned binary numbers; 1's and 2's complement representations; Addition and subtraction with signed binary; Range of signed and unsigned binary numbers.
π Lecture Summary
Binary to Decimal conversion
Most real-world quantities are represented in the Decimal Number System, while Digital Systems are based on the Binary Number System. Therefore, when converting from the Digital Domain to the real-world, Binary numbers must be represented in terms of their Decimal equivalents.
1. Sum-of-Weights Method The Sum-of-Weights method sums the weights of the Binary Digits (bits) of a Binary number to represent it in Decimal. An extended expression is written in terms of the Binary Base Number 2 and the weights of the binary bits. The weights correspond to each binary bit which are multiplied by the corresponding binary value. Binary bits having the value 0 do not contribute any value towards the final sum expression.
π Definition β Sum-of-Weights method: A conversion method where the decimal equivalent of a binary number is found by multiplying each binary digit by its positional weight (power of 2) and summing the results.
π Formula: Decimal = Ξ£ (bit Γ 2^position) for each bit position, where position starts at 0 from the rightmost (least significant) bit.
π Example: Binary number 10110β 10110β = 1 Γ 2β΄ + 0 Γ 2Β³ + 1 Γ 2Β² + 1 Γ 2ΒΉ + 0 Γ 2β° = 16 + 0 + 4 + 2 + 0 = 22
2. Sum-of-non-zero terms The Sum-of-non-zero terms method is a quicker method to determine decimal equivalents of binary numbers without writing an expression. The weights of non-zero binary bits are summed, as the weights of zero binary bits do not contribute. The weights of binary bits starting from the rightmost least significant bit is 1, then 2, 4, 8, 16, 32, etc. towards the left. In binary number system, weights of successive bits increase by a factor of 2 towards the left and decrease by a factor of 2 towards the right.
π Example: 10011β = 16 + 2 + 1 = 19
π Example: 1011.101β = 8 + 2 + 1 + Β½ + 1/8 = 11 + 5/8 = 11.625
Decimal to Binary conversion
Conversion from Decimal to Binary number system is essential to represent real-world quantities in terms of Binary values.
1. Sum-of-Weights The Sum-of-Weights method for decimal-to-binary conversion requires finding the highest weight included in the sum representing the decimal equivalent. A Binary 1 is marked to represent the bit that contributed its weight, and the weight is subtracted from the sum. This process repeats until the sum term becomes zero. The binary 1s and 0s represent bits that contributed their weight and bits that did not, respectively.
π Example: Converting 411 to Binary
| Sum Term | Highest Weight | Binary Number | Sum Term = Sum Term β Highest Weight |
|---|---|---|---|
| 411 | 256 | 100000000 | 155 |
| 155 | 128 | 110000000 | 27 |
| 27 | 16 | 110010000 | 11 |
| 11 | 8 | 110011000 | 3 |
| 3 | 2 | 110011010 | 1 |
| 1 | 1 | 110011011 | 0 |
Result: 411 = 110011011β
π Example: Converting 392 to Binary
| Sum Term | Highest Weight | Binary Number | Sum Term = Sum Term β Highest Weight |
|---|---|---|---|
| 392 | 256 | 100000000 | 136 |
| 136 | 128 | 110000000 | 8 |
| 8 | 8 | 110001000 | 0 |
Result: 392 = 110001000β
2. Repeated Division-by-2 The Repeated Division-by-2 method allows decimal numbers of any magnitude to be converted into binary. The decimal number is repeatedly divided by 2 (the Base number). A quotient and a remainder are generated at each step. The remainder values are noted, and the quotient is divided again by 2. The process stops when the quotient value becomes zero. The remainders, read from bottom to top, give the binary equivalent.
π Example: Converting 392 to Binary using Repeated Division-by-2
| Number | Quotient after division | Remainder after division |
|---|---|---|
| 392 | 196 | 0 |
| 196 | 98 | 0 |
| 98 | 49 | 0 |
| 49 | 24 | 1 |
| 24 | 12 | 0 |
| 12 | 6 | 0 |
| 6 | 3 | 0 |
| 3 | 1 | 1 |
| 1 | 0 | 1 |
Reading remainders from bottom to top: 110001000β
Converting Decimal fractions to Binary
1. Sum-of-Weights for Fractions The Sum-of-Weights method applied to decimal fractions works by finding the highest weight (negative power of 2) included in the decimal fraction.
π Example: Converting 0.625 to Binary
| Sum Term | Highest Weight | Binary Number | Sum Term = Sum Term β Highest Weight |
|---|---|---|---|
| 0.625 | 0.500 | 0.100 | 0.125 |
| 0.125 | 0.125 | 0.101 | 0 |
Result: 0.625 = 0.101β
2. Repeated Multiplication-by-2 Method The Repeated Multiplication-by-2 method converts decimal fractions to binary. The number is repeatedly multiplied by the Base Number (2). A new number having an Integer part and a Fraction part is generated after each multiplication. The Integer part is noted down, and the fraction part is multiplied by 2 again. The process repeats until the fraction term becomes zero. Reading the Integer column from top to bottom gives the binary equivalent.
π Example: Converting 0.625 to Binary using Repeated Multiplication-by-2
| Number | Integer part after multiplication | Fraction part after multiplication |
|---|---|---|
| 0.625 | 1 | 0.25 |
| 0.25 | 0 | 0.5 |
| 0.5 | 1 | 0.0 |
Reading Integer column from top to bottom: 0.101β
Binary Arithmetic
Digital systems use the Binary number system to represent numbers and must perform standard arithmetic operations.
1. Binary Addition Binary Addition is identical to Decimal Addition. Adding two binary bits generates a Sum bit and a Carry bit. Four possibilities exist when two single bits are added together.
π Single Bit Addition Table:
| First Number | Second Number | Sum | Carry |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 1 | 1 | 0 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 1 |
The fourth addition (1+1) results in 2, which is 10β in binary, requiring two digits: Sum=0, Carry=1.
π Example: Adding multiple binary numbers
1 1 0 1 (Carry row)
1 0 1 1 (11)
1 1 0 (06)
1 0 0 0 (08)
1 1 (03)
----------
1 1 1 0 0 (28)
2. Binary Subtraction Binary Subtraction is identical to Decimal Subtraction. Subtracting two single bit binary numbers results in a Difference bit and a Borrow bit.
π Single Bit Subtraction Table (second number subtracted from first):
| First Number | Second Number | Difference | Borrow |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 1 | 1 | 1 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 0 |
When subtracting 1 from 0, a Borrow is required to make the first digit equal to 2, giving a Difference of 1.
3. Binary Multiplication Binary Multiplication is similar to Decimal multiplication. Four possible combinations of two single bit binary numbers exist:
| First Number | Second Number | Product |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 1 |
π Example: 1101 Γ 101
1101
Γ 101
-----
1101 (1st product term)
0000 (2nd product term)
1101 (3rd product term)
-----
1000001
4. Binary Multiplication by Shifting Left Binary Multiplication by shifting left: A left shift by a single bit is equivalent to multiplication by 2. A left shift by two bits is equivalent to multiplication by 4. The multiplication factor is determined by 2^n where n is the number of bit shifts.
π Example:
- 00011 (3) original binary number
- 00110 (6) shifted left by 1 bit (Γ2)
- 01100 (12) shifted left by 2 bits (Γ4)
- 11000 (24) shifted left by 3 bits (Γ8)
5. Binary Division Division in binary follows the same procedure as decimal division.
π Example: 1101 Γ· 101
10
101 | 1101
101
---
011
000
---
11
Result: 10β with remainder 11β
6. Binary Division by Shifting Right Binary Division by shifting right: A right shift by a single bit is equivalent to division by 2. A right shift by two bits is equivalent to division by 4. The division factor is determined by 2^n where n is the number of bit shifts.
π Example:
- 10100 (20) original binary number
- 01010 (10) shifted right by 1 bit (Γ·2)
- 00101 (5) shifted right by 2 bits (Γ·4)
Signed and Unsigned Binary Numbers
Digital systems handle both positive and negative numbers. In a digital system that uses the Binary number system, positive and negative signs are represented in terms of binary 0 and 1. The digital system sets aside the most significant digit (bit) to represent the sign:
- MSB set to 1 indicates a negative number
- MSB set to 0 indicates a positive number
Thus +13 and -13 are represented as 01101 and 11101 respectively. This representation is known as the Signed-Magnitude representation.
Digital systems also handle Unsigned numbers, which are assumed to be positive and do not have the most significant sign bit. Thus 11101β represents -13 in signed binary and 29 in unsigned binary. A digital system must be notified beforehand whether to treat a binary number as signed or unsigned.
1's & 2's complement
A better way to handle signed numbers is to represent negative signed numbers in their 2's complement form. This allows direct manipulation of positive as well as negative numbers without having to worry about setting the MSB for sign.
π Definition β 1's complement: Obtained by simply inverting all the bits of a binary number.
π Definition β 2's complement: Obtained by first taking the 1's complement of a number and then adding a 1.
π Example: Obtaining 2's complement of 13
01101 The number 13
10010 1's complement of 13 (invert all bits)
+ 1
10011 2's complement of 13
In a 2's complement number system, all negative numbers are represented in their 2's complement form, and all positive numbers are represented in their actual form. Negative numbers can be identified by their MSBs which are set to 1. Thus +13 is 01101 and -13 is 10011.
π‘ Why this matters: Using 2's complement allows addition and subtraction to be performed by the same circuit, simplifying digital system design.
π Example: +13 + (-13) = 0
01101 (+13)
10011 (-13 in 2's complement)
-----
100000 (carry discarded, result is 00000 = 0)
π Example: +7 + (-13) = -6
10011 (-13 in 2's complement)
00111 (+7)
-----
11010 (result = -6 in 2's complement)
To find the magnitude of 11010:
11010 Original number
00101 1's complement
+ 1
00110 2's complement = 6
Addition and Subtraction Operations with Signed Binary
An additional benefit of using 2's complement representation is that both add and subtract operations can be performed by addition.
Four cases of adding/subtracting numbers using 2's complement:
Both numbers are positive:
0101 (+5)
0010 (+2)
-----
0111 (+7)
Both numbers are negative:
1011 (-5)
1110 (-2)
-----
11001 (-7, carry from MSB discarded)
One number positive, its magnitude larger than the negative number:
0101 (+5)
1110 (-2)
-----
10011 (+3, carry from MSB discarded)
One number positive, its magnitude smaller than the negative number:
1011 (-5)
0010 (+2)
-----
1101 (-3)
These examples demonstrate that add and subtract operations can be carried out by an adder circuit if numbers are represented in their 2's complement form. A separate circuit to perform subtractions is not required.
Range of Signed and Unsigned Binary Numbers
Three different types of Binary representations have been discussed: Unsigned Binary (only positive numbers), Sign-Magnitude (both positive and negative), and 2's complement signed (both positive and negative). Each representation can represent a certain range of binary numbers determined by the total number of bits used.
A 3-bit unsigned binary number can have values ranging between 000 and 111. Adding 100 and 111 results in 1011 (out of range for 3 bits). A 4-bit sign magnitude number can handle numbers between -7 and +7. A 4-bit 2's complement signed number range is between -8 to +7.
π Range of values represented by 4-bit Binary representations:
| Decimal | Sign-Magnitude | 2's Complement | Unsigned |
|---|---|---|---|
| -8 | 1000 | ||
| -7 | 1111 | 1001 | |
| -6 | 1110 | 1010 | |
| -5 | 1101 | 1011 | |
| -4 | 1100 | 1100 | |
| -3 | 1011 | 1101 | |
| -2 | 1010 | 1110 | |
| -1 | 1001 | 1111 | |
| 0 | 0000 | 0000 | 0000 |
| 1 | 0001 | 0001 | 0001 |
| 2 | 0010 | 0010 | 0010 |
| 3 | 0011 | 0011 | 0011 |
| 4 | 0100 | 0100 | 0100 |
| 5 | 0101 | 0101 | 0101 |
| 6 | 0110 | 0110 | 0110 |
| 7 | 0111 | 0111 | 0111 |
Range Formulas (where n = number of bits):
- Signed Magnitude: Range is (2^n-1 - 1) to -(2^n-1 - 1)
- 2's complement signed: Range is (2^n-1 - 1) to -(2^n-1)
- Unsigned: Range is 0 to (2^n - 1)
β Key Takeaways
The two primary methods for binary-to-decimal conversion are Sum-of-Weights (writing out powers of 2) and Sum-of-non-zero terms (adding only weights where binary digits are 1). For decimal-to-binary conversion of integers, use Repeated Division-by-2 (reading remainders bottom-to-top), and for fractions use Repeated Multiplication-by-2 (reading integer parts top-to-bottom). Binary arithmetic operations follow identical rules to decimal, but multiplication and division can be efficiently performed by shifting left or right by the appropriate number of bits. Signed binary numbers require special handling, and the 2's complement representation is the most efficient method because it allows both addition and subtraction to be performed using only an adder circuit. Remember the range limitations: for n bits, unsigned numbers range from 0 to 2^n-1, signed magnitude ranges from -(2^n-1-1) to +(2^n-1-1), and 2's complement ranges from -(2^n-1) to +(2^n-1-1).
π§ Quick Revision Questions
- Convert the binary number 11011.011β to its decimal equivalent using the Sum-of-Weights method.
- Convert the decimal number 57 to binary using the Repeated Division-by-2 method.
- Convert the decimal fraction 0.4375 to binary using the Repeated Multiplication-by-2 method.
- What is the 2's complement representation of -9 using 5 bits, and what is the decimal value represented by the 2's complement number 10110?
- What are the valid number ranges for a 5-bit unsigned number, a 5-bit sign-magnitude number, and a 5-bit 2's complement number?
π Lecture 3 β NUMBER SYSTEMS
π Overview: This lecture examines number representation and arithmetic in digital systems, focusing on overflow conditions in binary addition, floating-point number formats for representing very large and very small values, and the hexadecimal number system as a compact notation for binary strings. Understanding these concepts is essential for designing reliable digital circuits and correctly interpreting computational results.
ποΈ Topics Covered
The lecture begins by defining overflow conditions in binary arithmetic and determining overflow for 2's complement numbers through example analysis. It then introduces floating-point numbers, explaining decimal and binary floating-point formats, biased exponent representation, and arithmetic operations on floating-point numbers. The 64-bit double-precision format is briefly covered. Finally, the hexadecimal number system is presented, including counting, conversions between binary, decimal, and hexadecimal, and hexadecimal addition and subtraction.
π Lecture Summary
Range of Numbers and Overflow
When arithmetic operations such as Addition, Subtraction, Multiplication and Division are performed on numbers, the results generated may exceed the range of values specified by the Binary representations. The values that exceed the specified range cannot be correctly represented and are considered as Overflow values.
For example, a 3-bit Unsigned representation can correctly represent Unsigned Binary values in the range 0 to 2Β³-1 (0 to 7). Adding 3-bit Unsigned 010 (2) to another 3-bit Unsigned 111 (7) results in 1001 (9) which exceeds the 3-bit unsigned range and is considered to be an Overflow. Similarly, 1011 (-5) and 1100 (-4) values represented in 4-bit 2's complement form when added together result in 10111 (-9) which exceeds the 4-bit 2's complement range of values (2β΄β»ΒΉ-1) and -(2β΄β»ΒΉ) (7 to -8) and is considered as an Overflow.
Determining Overflow Conditions for 2's Complement Numbers
The Overflow condition can be easily determined when two numbers represented in 2's Complement form are added together. Analysis of the four addition operations indicates that Overflow conditions can be determined by looking at the most significant sign bits of the two numbers to be added together and the most significant sign bits of the sum result.
In examples where an Overflow has occurred, the sign bits of both the numbers are the same, indicating both numbers to be positive or negative respectively. The sign bit of the sum term in both cases is opposite to the signs of the two numbers being added together, which can never be. Thus the erroneous sign bits indicate the Overflow conditions.
Case 1: Both numbers are positive 0101 (+5) + 0100 (+4) = 1001 (-7) π Definition β Overflow Condition for 2's Complement Addition: When both numbers have the same sign and the result has the opposite sign, an overflow has occurred.
Case 2: Both numbers are negative 1011 (-5) + 1100 (-4) = 10111 (discard carry β +7) The result indicates a positive number as the most significant bit is 0, which is incorrect.
Case 3: Positive number magnitude larger than negative number magnitude 0101 (+5) + 1100 (-4) = 10001 (discard carry β +1) β Correct result.
Case 4: Negative number magnitude larger than positive number magnitude 1011 (-5) + 0100 (+4) = 1111 (-1) β Correct result.
π‘ Why this matters: Being able to detect overflow is critical for ensuring the correctness of arithmetic operations in processors and digital systems.
Floating-Point Numbers
Modern computers can handle large binary numbers such as 64-bit unsigned numbers; the maximum decimal number that can be represented using the 64-bit unsigned representation is 2βΆβ΄-1, which is nearly equal to 1.84 Γ 10ΒΉβΉ.
The floating-point number system, based on scientific notation, is capable of representing very large and very small numbers without having to increase the number of bits. Numbers having an integer part and a fraction part are also easily represented using the Floating-Point representation.
Floating point numbers are defined using certain standards. The ANSI/IEEE Standard 754 defines a 32-bit Single-Precision Floating Point format for binary numbers.
32-bit Single-Precision F.P. Format:
- S (1 bit) β Sign bit (0 = positive, 1 = negative)
- Exponent (8 bits) β Represents the exponent
- Mantissa (23 bits) β Represents the magnitude of the number
Decimal Number Floating-Point Format
A 15-digit decimal floating point format uses:
- Sign (1 digit) β +/-
- Exponent (2 digits)
- Mantissa (12 digits)
The number 6918.3125 can be written as 6.9183125 Γ 10Β³. The decimal point is moved to the extreme left of the number (normalized) so that the magnitude is represented by a fraction part. The number 0.69183125 Γ 10β΄ is represented in decimal f.p. notation as: + 04 691831250000
Using this 15-digit notation, the largest number that can be represented is 0.999,999,999,999 Γ 10βΉβΉ.
Representing Negative Exponent Values
The 15-digit decimal floating-point format does not allow negative exponents. Two options are available:
- Increase the Exponent field by one digit to allow for the sign
- Use a Biased Exponent scheme β add the value 50 to the exponent and write the result in the exponent field
Using this biased scheme, the maximum positive exponent value that can be represented is 49 (49 + 50 = 99). The smallest exponent that can be represented is -50 (-50 + 50 = 0). The range of decimal numbers becomes 0.999,999,999,999 Γ 10β΄βΉ to 0.999,999,999,999 Γ 10β»β΅β°.
Representing Zero and Infinity Values
The number zero can be represented by setting all Mantissa digits to 0. The solution to represent infinity is to set aside a biased exponent value. By allowing numbers having the maximum and minimum exponent values to be 49 and -48 instead of 49 and -50, and selecting 49 as the biased number: Biased exponent values range between 98 (49+49) and 01 (-48+49). The biased exponent value 00 can be used to represent zero, and 99 can be used to represent infinity.
Representing a Decimal fraction number in 32-bit Single-Precision Floating Point format
The 32-bit Single Precision Floating Point format represents the Exponent value as a Biased Number, reserving the exponent values 0 and 255 to represent the value zero and infinity respectively. The range of exponent value is from +127 to -126.
Stepwise representation of decimal number 6918.3125:
- Convert Decimal to Binary: 6918.3125ββ = 1101100000110.0101β
- Normalize: 1.1011000001100101 Γ 2ΒΉΒ²
- Represent exponent in Biased-127: 12 + 127 = 139 = 10001011β
Result: 0 10001011 10110000011001010000000
The Mantissa is 10110000011001010000000 instead of 11011000001100101000000 because all binary numbers that are normalized always have a leading 1. In the f.p. format the leading 1 is not written, however it is taken into account in all calculations. The leading 1 which is not written is known as a hidden 1.
Arithmetic Operations on Floating Point Numbers
Arithmetic operations can be directly performed on floating point numbers by manipulating the mantissa and exponent parts.
Addition/Subtraction: Two floating point numbers can be added by adding together their mantissas, ensuring that the exponent parts of both numbers are the same. If the exponents are not equal, the decimal point has to be adjusted for one number.
Multiplication: Performed by multiplying the mantissas together and adding their corresponding exponents.
Division: Performed by dividing the mantissa parts and subtracting the corresponding exponents.
Examples:
- 723 + 134 = exponent 2, mantissa 8.57
- 723 (exp 2, mantissa 7.23) + 2015 (exp 3, mantissa 2.015): Adjust first number to exp 3, mantissa 0.723 β result exp 3, mantissa 2.738
- 723 Γ 34 = exponent 3, mantissa 24.582
- 697 Γ· 41 = exponent 1, mantissa 1.7
64-bit Double-Precision Floating Point format
The 32-bit Single precision floating point representation can represent the largest positive or negative number of the order of 2ΒΉΒ²β· and the smallest of the order of 2β»ΒΉΒ²βΆ. To represent larger numbers, 64-bit Double Precision floating point format is used. It sets aside 11 bits to represent the exponent as Biased-1023 and a mantissa of 52 bits, with a single bit for the sign.
Hexadecimal Numbers
The Hexadecimal number system is a base 16 number system and therefore has 16 digits and is used primarily to represent binary strings in a compact manner. Hexadecimal is not used by a Digital System but for our convenience. Each Hexadecimal digit can represent a 4-bit Binary Number.
| Decimal | Binary | Hex | Decimal | Binary | Hex |
|---|---|---|---|---|---|
| 0 | 0000 | 0 | 8 | 1000 | 8 |
| 1 | 0001 | 1 | 9 | 1001 | 9 |
| 2 | 0010 | 2 | 10 | 1010 | A |
| 3 | 0011 | 3 | 11 | 1011 | B |
| 4 | 0100 | 4 | 12 | 1100 | C |
| 5 | 0101 | 5 | 13 | 1101 | D |
| 6 | 0110 | 6 | 14 | 1110 | E |
| 7 | 0111 | 7 | 15 | 1111 | F |
Counting in Hexadecimal
Counting in Hexadecimal is similar to other number systems. The maximum value represented by a single Hexadecimal digit is F (decimal 15). Decimal 16 is represented as 10ββ or 10H.
Binary to Hexadecimal Conversion
The Binary string is divided into small groups of 4-bits starting from the least significant bit. Each 4-bit binary group is replaced by its Hexadecimal equivalent.
Example: 11010110101110010110β β 1101 0110 1011 1001 0110 β D6B96ββ
Binary strings which cannot be exactly divided into a whole number of 4-bit groups have 0's appended in the most significant bits to complete a group.
Example: 1101100000110β β 0001 1011 0000 0110 β 1B06ββ
Hexadecimal to Binary Conversion
Each digit of the Hexadecimal number is replaced by an equivalent binary string of 4-bits.
Example: FD13ββ β 1111 1101 0001 0011β
Decimal to Hexadecimal Conversion
Method 1 (Indirect): Convert decimal to binary, then binary to hexadecimal.
Method 2 (Repeated Division-by-16): The decimal number is continuously divided by 16.
Example: Converting 2096ββ to Hexadecimal:
- 2096 Γ· 16 = 131 remainder 0
- 131 Γ· 16 = 8 remainder 3
- 8 Γ· 16 = 0 remainder 8 Result: 830ββ
Hexadecimal to Decimal Conversion
Method 1 (Indirect): Convert hexadecimal to binary, then binary to decimal.
Method 2 (Sum-of-Weights): A Hexadecimal number can be directly converted into Decimal by using the sum of weights method.
Example: CA02ββ = (C Γ 16Β³) + (A Γ 16Β²) + (0 Γ 16ΒΉ) + (2 Γ 16β°) = (12 Γ 4096) + (10 Γ 256) + (0 Γ 16) + (2 Γ 1) = 49152 + 2560 + 0 + 2 = 51714ββ
Hexadecimal Addition and Subtraction
Numbers represented in Hexadecimal can be added and subtracted directly without converting them into decimal or binary equivalents.
Hexadecimal Addition Example:
1 β Carry
2 A C 6
+ 9 2 B 5
-----------
B D 7 B
Hexadecimal Subtraction Example:
1 1 1 β Borrow
9 2 B 5
- 2 A C 6
-----------
6 7 E F
β Key Takeaways
Overflow in 2's complement addition is detected when the sign bits of both operands are the same but the result's sign bit is opposite. Floating-point representation using a sign bit, biased exponent, and mantissa with a hidden 1 allows computers to handle a vast range of numbers including fractions and extremely large/small values. The IEEE 754 standard defines single-precision (32-bit, 8-bit exponent biased by 127) and double-precision (64-bit, 11-bit exponent biased by 1023) formats. Hexadecimal (base-16) provides a compact human-readable notation for binary strings, with each hex digit exactly representing four binary bits. Arithmetic operations on floating-point numbers require exponent alignment for addition/subtraction, while multiplication adds exponents and division subtracts them.
π§ Quick Revision Questions
- How can you detect an overflow condition when adding two 2's complement numbers?
- What is the purpose of using a biased exponent in floating-point representation, and what bias value is used for 32-bit single precision?
- What is a "hidden 1" in the IEEE 754 floating-point format, and why is it not explicitly stored in the mantissa?
- Convert the binary number 1101100000110 to its hexadecimal equivalent.
- Describe the steps to perform floating-point addition when the two numbers have different exponents.