General Revision of Chapter 2and 3-1

Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

University of Algiers 1 Department of computer science Machine Structure I

General revision for chapters 2 and 3

Chapter 2: Number Systems


- Presentation of decimal, binary, octal, and hexadecimal systems.
Decimal: base 10, numbers: from 0-9, Binary: base 2, numbers: 0
and 1, Octal: base 8, numbers: 0-7, Hexadecimal: base 16, numbers:
from 0 to 9 and characters from A-F.

- Conversion between these different systems.


• Conversion from decimal to any other system is
accomplished by successively dividing the number by the
target base and keeping track of the remainder until the
quotient is zero.
• Conversion from any base to decimal is accomplished by
successively multiplying each digit by its base weight and
adding them.
• Conversion between systems other than decimal, happens
through converting to decimal first, then to the destined
base.
• Special transcoding can happen when the original or
destined base is a power of 2 (16 = 24, 8 = 23, 4 = 22, 2 =
21).

- Basic operations in the binary system:


Addition Subtraction
1 + 0 + 0 = 01 𝑠𝑢𝑚 1 𝑐𝑎𝑟𝑟𝑦 0 0−0=0
1 + 1 + 0 = 10 𝑠𝑢𝑚 0 𝑐𝑎𝑟𝑟𝑦 1 1−1=0
1 + 0 + 1 = 10 𝑠𝑢𝑚 0 𝑐𝑎𝑟𝑟𝑦 1 1−0=1
1 + 1 + 1 = 11 𝑠𝑢𝑚 1 𝑐𝑎𝑟𝑟𝑦 1 0 − 1 = 𝑤𝑒 𝑏𝑜𝑟𝑟𝑜𝑤 1 𝑡𝑜 𝑔𝑒𝑡 10 − 1 = 1
1+1+1+1=
100 𝑠𝑢𝑚 0 1𝑠𝑡 𝑐𝑎𝑟𝑟𝑦 0 2𝑛𝑑 𝑐𝑎𝑟𝑟𝑦 1
Multiplication Division
0×0= 0 0÷1=0
0×1= 0 1÷1=1
1×0= 0
1×1= 1

DRs. ZAIRI AND MADI 2023-2024


University of Algiers 1 Department of computer science Machine Structure I

Chapter 3: Representation of Information


- Binary coding:
- Pure binary coding: straightforward binary encoding. Data is represented using only the binary
digits 0 and 1 without any additional encoding or transformation.
• The number of possible values is 2n where n is number of bits used in the representation.
• The range is [0, 2n-1]
• The minimum value is 0
• The maximum value is 2n-1
In order to know how many bits are required to represent any decimal number in binary, we use
the following equation: ln(N+1)/ln(2), where N is the decimal number

- Reflected binary code (or Gray code): is a binary numeral system in which two successive
values differ in only one bit.
Converting from binary to gray code:
1. The most significant bit (left-most) in the Gray code is the same as the corresponding
MSB in the binary number.
2. Going from left to right, add each adjacent pair of binary code bits to get the next
Gray code bit. Discard carries.
Converting from gray to binary:
1. The most significant bit (left-most) in the binary code is the same as the corresponding
bit in the Gray code.
2. Add each binary code bit generated to the Gray code bit in the next adjacent position.
Discard carries.

- BCD (Binary Coded Decimal: employs a 4-bit nibble to represent each decimal digit (0-9).

Converting from decimal to BCD: simply substitute the appropriate 4-bit code for each
decimal digit to convert any decimal number to BCD
Converting from BCD to decimal: Start at the right-most bit and break the code into
groups of four bits. Then write the decimal digit represented by each 4-bit group.

Adding in BCD:
1. Calculate the sum of each group of 4 bits without taking the carry to next group of four
bits (if generated)
2. Apply what we call corrections on the answers: from right to left on each group of four
bits that is greater than nine (1001), by adding six (0110). If a carry is generated at the
this step, we can pass it to the next group.
3. Corrections are also applied in case a carry is generated, to the block that generated the
carry: by adding six also.
4. The final carry from the last group before corrections is also kept.
DRs. ZAIRI AND MADI 2023-2024
University of Algiers 1 Department of computer science Machine Structure I

Subtraction in BCD:
1. Subtract each block of 4-bits from right to left, and borrow a 1 if from the next block
if necessary.
2. If the answer of any 4-bit group is greater than 9 then apply correction by subtracting
six (0110).

- Excess-3 code: Natural BCD code + 3


Addition in Excess-3:
1. add the bits from right to left
2. correct the blocks of four bits in cases:
a. if there is a carry generated from the block: we add three (0011)
b. if not, then subtract three (0011)
c. the final carry that is generated from the final block is also corrected by adding
three (0011)
Subtraction in Excess-3:
first method:
1. Subtract the bits from right to left.
2. Correct each block of four bits:
a. If a 1 was borrowed at the MSB of the block, the result is not correct and we
need to subtract 3 (-11).
b. If not, then the result is correct and we add 3 (+11).
Second method (1’s complement method):
1. Convert the number B to 1’s complement
2. Add A+(B)1’sC, and if there is a final carry it will be added to the result.
3. The result obtained is in complement to 1:
- If A>B then the result is positive so it is correct and it is in XS3
- Otherwise then the result is negative, so it is necessary to calculate its complement to 1.

Decimal Binary Gray BCD EX-3 Decimal Binary Gray BCD Ex-3
0 0000 0000 0000 - 8 1000 1100 1000 1000
1 0001 0001 0001 - 9 1001 1101 1001 1001
2 0010 0011 0010 - 10 1010 1111 - 1010
3 0011 0010 0011 0011 11 1011 1110 - 1011
4 0100 0110 0100 0100 12 1100 1010 - 1100
5 0101 0111 0101 0101 13 1101 1011 - -
6 0110 0101 0110 0110 14 1110 1001 - -
7 0111 0100 0111 0111 15 1111 1000 - -

- Representation of characters:

DRs. ZAIRI AND MADI 2023-2024


University of Algiers 1 Department of computer science Machine Structure I

- EBCDIC code
- ASCII code
- UTF code.
- Representation of numbers:
1- Integer numbers:
- Unsigned representation.
This is the normal representation of binary numbers with signs. As we did in chapter 2.
- Signed representation with absolute value (signed magnitude form).
In this method, the MSB is considered a sign bit, 0 for a positive binary number and 1 for a
negative binary number.
- One's Complement
The positive number in 1’s complement is the same as the SM form.
The negative number in 1’s complement: we inverse the bits of the positive SM or the positive
1’s complement forms.
- Two's Complement
The positive number in 1’s complement is the same as the positive SM form and positive 1’s
complement forms.
The negative number in 2’s complement: we add 1 to negative 1’s complement form.
NB: we reserve the MSB to the sign 0=+, 1=-.
Here is the range of unsigned and signed binary numbers (8-bits)
Unsigned Signed integer numbers
numbers
Sign-Magnitude 1’s Complement 2’s Complement

Number of 2n 2n 2n 2n
8 8 8 8
possible 2 = 256 2 = 256 2 = 256 2 = 256
combinations
Number of 2n 2n-1 2n-1 2n
8 8 8-1 8
possible values 2 = 256 2 -1 = 255 2 = 255 2 = 256
(zero has two (zero has two
representations) representations)
Range of values 0-2n-1 -(2n-1-1), +(2n-1-1) -(2n-1-1), +(2n-1-1) -(2n-1), +(2n-1-1)
[0,255] [-127,+127] [-127,+127] [-128,+127]

Arithmetic operation of signed numbers (2’s complement)


Number are presented in 2’s complement form
Addition:
1. Both numbers positive: answer positive
2. Positive number > negative number: answer positive
3. Negative number > positive number: answer negative in 2’ complement form
4. Both negative numbers: answer negative in 2’s complement form
Notes:

DRs. ZAIRI AND MADI 2023-2024


University of Algiers 1 Department of computer science Machine Structure I

1. Discard any final carry. In case more than two number are added, we add the first two
number, then add the third number to the sum and so on.
2. An overflow occurs when adding two numbers resulting in more bits being needed to
represent the result than the two numbers themselves, as seen by an erroneous sign bit.
3. Overflow is signaled when the result's sign bit differs from the sign bits of the integers
being added (happens when 2 positive or 2 negative numbers are added)

Subtraction:
To subtract two signed numbers we change the sign of the subtrahend using 2’s complement and
add it to the minuend. Discard any final carry bit.

2- Fractional numbers:
- Fixed-point.
To get the fixed-point representation:
a. Convert the integer part using successive division until the quotient is 0.
b. Convert the fractional part using successive multiplication until the fraction is 0.
c. Write the resulted real and fractional part in binary, and separate both parts by the point.
- Floating-point (IEEE 754 standard)
In decimal the scientific notation of real numbers follows this form:
𝑉𝑎𝑙𝑢𝑒 = 𝑠𝑖𝑔𝑛 × 𝑚𝑎𝑛𝑡𝑖𝑠𝑠𝑎 × 10±𝑟𝑒𝑎𝑙 𝑒𝑥𝑝𝑜𝑛𝑒𝑛𝑡
As for the binary system, the scientific notations for representing floating point numbers is:
𝑉𝑎𝑙𝑢𝑒 = 𝑠𝑖𝑔𝑛 × 𝑚𝑎𝑛𝑡𝑖𝑠𝑠𝑎 × 2±𝑟𝑒𝑎𝑙 𝑒𝑥𝑝𝑜𝑛𝑒𝑛𝑡
The ANSI/IEEE Standard 754-1985 specifies the format for binary floating-point numbers in
three ways: single-precision (32 bits), double-precision (64 bits), and extended-precision (128
bits).
In the standard format for a single-precision binary number:
sign bit (S): 1 bit, the exponent (E): includes the next 8 bits, and the mantissa or fractional part
(F): includes the remaining 23 bits

The exponent is put in the biased form by adding 127 to the actual exponent in case 8 bits are
allocated for the exponent. In general, the bias is a result of:
2𝑝−1 − 1 𝑤ℎ𝑒𝑟𝑒 𝑝 𝑖𝑠 𝑡ℎ𝑒 𝑛𝑢𝑚𝑏𝑒𝑟 𝑜𝑓 𝑡ℎ𝑒 𝑏𝑖𝑡𝑠 𝑎𝑙𝑙𝑜𝑐𝑎𝑡𝑒𝑑 𝑓𝑜𝑟 𝑡ℎ𝑒 𝑒𝑥𝑝𝑜𝑛𝑒𝑛𝑡
Performing arithmetic operations on IEEE 754 floating point numbers requires following these
steps:
1. de-normalizing the two floating point numbers returning the biased exponent to its real
form.

DRs. ZAIRI AND MADI 2023-2024


University of Algiers 1 Department of computer science Machine Structure I

2. In addition or subtraction, we get the exponents to be the same, to the higher exponent.
Then we add/subtract the two exponents and add/subtract the mantissas as well.
3. In multiplication, we add the two exponents, and multiply the mantissas.
4. In division, we subtract the two exponents, and divide the mantissas.
5. Finally, we normalize the result and write it in the IEEE 754 standard.

Extra Exercises:

Exercise 1:
• Provide the number of values that can be represented and the range of unsigned integers using
4, 8, 16 and 32 bits
• How many bits (minimum) are required to represent the following numbers as unsigned
integers:
a) (257)10 ; b) (2048)10 ;

Exercise 2: Determine the base (T, X, Y and Z) in which the following numbers are expressed:
• (24)T = (14)10
• (13)X = (7)10
• (70)Y = (56)10
• (190)Z = (400)10
Exercise 3: Complete the following table:

Decimal Pure Binary BCD GRAY Excess-3


178
110110
0100 1000 0110 0111

Exercise 4: Perform the following operations using BCD and Excess-3 arithmetic’s: 788 + 879;
599-015,
Exercise 5:
1. Represent (61)10 et –(61)10 on a byte using sign and absolute value representation (sign magnitude
form).
2. Add (61)10 et –(61)10 in sign magnitude form.
3. Represent (61)10 et –(61)10 on one byte using 2's Complement representation.
4. Perform the addition (61)10 et –(61)10 in 2’s complement. What is your conclusion?

Exercise 6: Subtract (a) (−64)10 from (-32)10 and (b) (29.A)16 from (4F.B)16.
Use 2’s complement arithmetic

Exercise 7: Represent the number -127.192 using the IEEE 754 floating point representation in
both single and double precision.

DRs. ZAIRI AND MADI 2023-2024


University of Algiers 1 Department of computer science Machine Structure I

Exercise 8: 2 numbers A and B represented in three positions as follows:


A=(a3 a2 a1)5 ; B=(b3 b2 b1)7
1- What are the possible values for the coefficients ai, bi?

Knowing that A+B=(138)9 , A-B=(200)6.


2- Find the values of the coefficients a3, a2, a1, b3, b2, b1.
3- Transform A and B to binary, then calculate A+B et A-B.

DRs. ZAIRI AND MADI 2023-2024

You might also like