CAO Mid
CAO Mid
1. Arithmetic Operations: The ALU performs basic arithmetic operations like addition,
subtraction, multiplication, and division, which are essential for calculations in various
applications.
2. Logical Operations: It executes logical operations (AND, OR, XOR, NOT) that allow the
CPU to make decisions based on conditions, enabling complex program logic.
3. Shift Operations: The ALU shifts bits to the left or right within binary numbers, which aids
in efficient data manipulation and helps perform tasks like multiplication and division by
powers of two.
4. Comparison Operations: It compares values to determine conditions (greater than, less than,
equal to), enabling decision-making and branching in program execution.
In Sign Magnitude representation, the leftmost bit (most significant bit) indicates the sign of
the number: 0 for positive and 1 for negative.
The remaining bits represent the magnitude (absolute value) of the number.
For example, in an 8-bit system:
o +5 would be represented as 0000 0101
o -5 would be represented as 1000 0101
Advantages: Simple to understand and directly represents positive and negative values.
Limitations: Arithmetic operations (like addition) are complex to perform due to the need to
account for both sign and magnitude separately.
2’s Complement is a binary system used for representing both positive and negative integers
in a straightforward manner.
To represent a negative number, invert all bits of its positive counterpart (1’s complement)
and then add 1 to the result.
For example, in an 8-bit system:
o +5 is 0000 0101
o -5 (2’s complement of +5) is 1111 1011
Benefits: Simplifies arithmetic operations (especially addition and subtraction) because there
is no need for separate sign handling. Negative values are seamlessly integrated into binary
arithmetic.
Range: In an n-bit system, 2’s complement can represent values from -2^(n-1) to 2^(n-1) - 1.
1. Sign Bit:
o Indicates whether the number is positive or negative.
o Typically, 0 represents a positive number, and 1 represents a negative number.
3. Exponent:
o Represents the power to which the base (usually 2 in binary systems) is raised.
o Allows the number to represent a wide range of values by adjusting the scale of
the mantissa.
4. Given x=1011 and y=1001 in 2’s complement i.e (x=-5) and (y=-1) draw and
compute the product p=xy with booth algorithm and flowchart?
To compute the product p=x⋅yp = x \cdot yp=x⋅y where x=−5x = -5x=−5 and y=−1y = -1y=−1 in 2's
complement, we'll follow Booth's Multiplication Algorithm for binary numbers. Here’s the solution along
with the step-by-step algorithm and a flowchart.
Step-by-Step Calculation
Initial Values:
A=0000A = 0000A=0000
Q=1001Q = 1001Q=1001
Q−1=0Q_{-1} = 0Q−1=0
x=1011x = 1011x=1011 (i.e., -5)
Iteration 1
Iteration 2
Iteration 3
Iteration 4
Final Product:
The result A Q=1111A \, Q = 1111AQ=1111, which is -5 in 2's complement, confirming that −5×−1=−5-5 \
times -1 = -5−5×−1=−5.
1. Start with A=0A = 0A=0, Q=yQ = yQ=y, Q−1=0Q_{-1} = 0Q−1=0, and load xxx.
2. Check Q0Q_0Q0 and Q−1Q_{-1}Q−1:
o If Q0=1Q_0 = 1Q0=1 and Q−1=0Q_{-1} = 0Q−1=0, subtract xxx from AAA.
o If Q0=0Q_0 = 0Q0=0 and Q−1=1Q_{-1} = 1Q−1=1, add xxx to AAA.
3. Perform Right Shift on A,Q,Q−1A, Q, Q_{-1}A,Q,Q−1.
4. Repeat steps 2-3 for nnn times.
5. End with A QA \, QAQ as the final product in 2’s complement form.
5. Show how the following floating point additions are perform (where
significant and mantisa are tracked to four decimal digit) show the result in
normalized form:
i. 5.566*10^2*7.777*10^3
ii. 3.344*10^1+8.877*10^-2
iii. 6.21*10^5/8.877*10^-1
To perform the floating point operations while tracking the significands (mantissas) to four decimal
digits and showing the results in normalized form, we will follow these steps for each operation:
To convert the decimal number (100.125)10(100.125)_{10}(100.125)10 into IEEE 754 single precision
floating-point representation, we will follow these steps:
Step 1: Convert the Decimal to Binary
(100.125)10=(1100100.001)2(100.125)_{10} = (1100100.001)_2(100.125)10=(1100100.001)2
To normalize the binary number, we express it in the form 1.x×2n1.x \times 2^n1.x×2n:
1. Sign bit:
o Since the number is positive, the sign bit is 000.
2. Exponent:
o The exponent in the normalized form is 666.
o IEEE 754 single precision uses a bias of 127127127:
133÷2=66 remainder 166÷2=33 remainder 033÷2=16 remainder 116÷2=8 remainder 08÷2=4 remain
der 04÷2=2 remainder 02÷2=1 remainder 01÷2=0 remainder 1133 \div 2 = 66 \text{ remainder } 1 \\
66 \div 2 = 33 \text{ remainder } 0 \\ 33 \div 2 = 16 \text{ remainder } 1 \\ 16 \div 2 = 8 \
text{ remainder } 0 \\ 8 \div 2 = 4 \text{ remainder } 0 \\ 4 \div 2 = 2 \text{ remainder } 0 \\ 2 \div 2
= 1 \text{ remainder } 0 \\ 1 \div 2 = 0 \text{ remainder }
1133÷2=66 remainder 166÷2=33 remainder 033÷2=16 remainder 116÷2=8 remainder 08÷2=4 remai
nder 04÷2=2 remainder 02÷2=1 remainder 01÷2=0 remainder 1
100100001000000000000001001000010000000000000010010000100000000000000
Final Result
01000010110010000100000000000000\boxed{0 10000101
10010000100000000000000}01000010110010000100000000000000
01000010110010000100000000000000\
boxed{01000010110010000100000000000000}01000010110010000100000000000000
7. Sketch and explain flowchart for multiplication for floating point numbers?
Creating a flowchart for multiplying floating point numbers involves breaking down the steps required to
perform the multiplication while adhering to the IEEE 754 floating-point standard. Below is an explanation
of each step along with a textual representation of a flowchart.
1. Input: Read two floating-point numbers in IEEE 754 format. Each number consists of a sign bit, an
exponent, and a mantissa.
2. Extract Components:
o Extract the sign bits, exponents, and mantissas from both numbers.
o The sign is typically represented by S1S_1S1 and S2S_2S2, the exponent by E1E_1E1 and
E2E_2E2, and the mantissa by M1M_1M1 and M2M_2M2.
6. Normalization:
o Normalize the result if necessary. This involves adjusting the mantissa so that it is in the form
1.x1.x1.x, and updating the exponent accordingly.
9. Output: Combine the sign, exponent, and mantissa to form the final result in IEEE 754 format.
csharp
Copy code
[Start]
|
v
[Input: Read two floating point numbers (A, B)]
|
v
[Extract sign, exponent, and mantissa]
|
v
[Determine sign of result]
|
v
[Add exponents]
|
v
[Multiply mantissas]
|
v
[Normalize the result]
|
v
[Check for overflow/underflow]
|
v
[Round the result]
|
v
[Output final result in IEEE 754 format]
|
v
[End]
Flowchart Explanation
Integer representation in computer systems is fundamental for data storage, processing, and
computational tasks. This representation can be categorized primarily into binary, octal, decimal, and
hexadecimal systems, with binary being the most prevalent in computing. Below, we will delve into the
various aspects of integer representation, focusing on binary representation, its types, and the significance of
signed and unsigned integers.
1. Binary Representation
Computers use the binary number system, which consists of only two digits: 0 and 1. Each binary digit (bit)
represents a power of two, allowing the representation of integers in a compact and efficient manner.
Binary Basics
A binary number is read from right to left, where each bit represents 2n2^n2n, with nnn starting at 0.
For example, the binary number 101121011_210112 represents:
1×23+0×22+1×21+1×20=8+0+2+1=11101 \times 2^3 + 0 \times 2^2 + 1 \times 2^1 + 1 \times 2^0 =
8 + 0 + 2 + 1 = 11_{10}1×23+0×22+1×21+1×20=8+0+2+1=1110
Unsigned Integers
Unsigned integers can only represent non-negative values (0 and positive integers).
For an nnn-bit unsigned integer, the range of values is from 000 to 2n−12^n - 12n−1.
o Example: For an 8-bit unsigned integer, the range is 000 to 255255255 (i.e., 28−12^8 -
128−1).
Signed Integers
The first bit (most significant bit, MSB) represents the sign of the integer (0 for positive, 1 for
negative), while the remaining bits represent the magnitude.
Example: In an 8-bit system:
o 000001010000010100000101 represents +5+5+5
o 100001011000010110000101 represents −5-5−5
Limitations: This method has two representations for zero: +0+0+0 (00000000) and −0-0−0 (10000000),
which can lead to complications.
Two's complement is the most widely used method for representing signed integers in computers.
The MSB still indicates the sign (0 for positive, 1 for negative), but negative values are represented
by inverting all bits of the absolute value (the positive version) and then adding 1 to the result.
Range: For an nnn-bit signed integer, the range is from −2n−1-2^{n-1}−2n−1 to 2n−1−12^{n-1} -
12n−1−1.
o Example: In an 8-bit system, the range is from −128-128−128 to 127127127.
To find −5-5−5:
1. Start with +5+5+5: 000001010000010100000101
2. Invert the bits: 111110101111101011111010
3. Add 111: 11111010+00000001=1111101111111010 + 00000001 =
1111101111111010+00000001=11111011
To work with integers in different bases (like binary, decimal, octal, or hexadecimal), conversions are
essential:
Decimal to Binary
Binary to Decimal
1. Multiply each bit by 2n2^n2n based on its position and sum the results.
Octal uses base 8 and can be converted from binary by grouping bits in sets of three (e.g.,
000000000 = 0, 001001001 = 1, ..., 111111111 = 7).
Hexadecimal uses base 16 and can be converted from binary by grouping bits in sets of four (e.g.,
000000000000 = 0, 000100010001 = 1, ..., 111111111111 = F).
Data Storage: Integers are used for counting, indexing, and as identifiers in databases.
Mathematical Operations: They are the basis for arithmetic operations in programming and
computer algorithms.
Control Structures: Integer values are commonly used in loops and conditional statements in
programming.
The subtrahend is (10011)2(10011)_2(10011)2. To find its 1's complement, we invert each bit.
(01100)2(01100)_2(01100)2
Step 2: Add the Minuend and the 1's Complement of the Subtrahend
markdown
Copy code
11011
+ 01100
-------
001111
Step 3: Handle the Carry
markdown
Copy code
001111
+ 1 (carry)
-------
010000
Step 4: Final Result
The result of the addition is (01000)2(01000)_2(01000)2. This represents the positive binary result of the
subtraction. The final result can be interpreted as:
(01000)2=(8)10(01000)_2 = (8)_{10}(01000)2=(8)10
To find the 2's complement of (10011)2(10011)_2(10011)2, we first find its 1's complement and then add
111.
markdown
Copy code
01100
+ 00001
-------
01101
(01101)2(01101)_2(01101)2
Step 2: Add the Minuend and the 2's Complement of the Subtrahend
markdown
Copy code
11011
+ 01101
-------
101000
Step 3: Handle the Carry
In 2's complement, if there is a carry out of the most significant bit, it is ignored. Thus:
(01000)2=(8)10(01000)_2 = (8)_{10}(01000)2=(8)10
10. Represent the decimal values 12-10 and 15 assign 8 bit numbers in following binary formats:
i. Sign magnitude
ii. 1’s complement
iii. 2’s complement
In sign magnitude representation, the most significant bit (MSB) is used as the sign bit, where 0 indicates a
positive number and 1 indicates a negative number. The remaining bits represent the magnitude.
1. Decimal 12:
o Binary: 000011000000110000001100 (Sign bit = 0, Magnitude = 12)
2. Decimal -10:
o Positive 10 in binary: 000010100000101000001010
o Sign bit: 1 (indicating negative)
o Result: 100010101000101010001010
3. Decimal 15:
o Binary: 000011110000111100001111 (Sign bit = 0, Magnitude = 15)
121212 → 000011000000110000001100
−10-10−10 → 100010101000101010001010
151515 → 000011110000111100001111
In 1's complement representation, the MSB is the sign bit. To get the negative representation, we invert all
bits of the positive representation.
1. Decimal 12:
o Binary: 000011000000110000001100
2. Decimal -10:
o Positive 10 in binary: 000010100000101000001010
o 1's complement (invert bits): 111101011111010111110101
3. Decimal 15:
o Binary: 000011110000111100001111
121212 → 000011000000110000001100
−10-10−10 → 111101011111010111110101
151515 → 000011110000111100001111
In 2's complement representation, the MSB is also the sign bit. To get the negative representation, we take
the 1's complement and add 1.
1. Decimal 12:
o Binary: 000011000000110000001100
2. Decimal -10:
o Positive 10 in binary: 000010100000101000001010
o 1's complement: 111101011111010111110101 (invert bits)
o Add 1:
Copy code
11110101
Copy code
1
11110110