MS1-chap1 - Part1
MS1-chap1 - Part1
2024-2025. Term 1
Machine Structure
Teaching staff
Students concerned
Faculty/Institute Département Year Speciality
New Technologies ING ING1 ING
Course objectives
The first objective of this chapter is to provide a comprehensive introduction to the
architecture of computers and initiate the student to the coding and representation of numbers.
The second objective is to familiarise the student with the notion of binary and machine code.
The third objective is to introduce the student to a mathematical support for the mastery of
binary (Boolean algebra).
1
Chapter 1: Part-1
Codification and
representation of numbers
2
1.1. Introduction :
Nowadays, information technology is part of every human activity. The computer is the most
widely used tool in the world. To understand how a computer works, we first need to understand how
it represents and processes information in general. In this chapter we will focus on the codification and
representation of numbers.
The machine only manipulates two binary values (0 and 1) to represent and process information, and
in particular numbers, which is why we will be focusing on binary codification and representation in
this chapter.
Each number X expressed in base B will be represented by a concatenation of the symbols 𝑋𝑖 in set E.
Examples :
Note:
To avoid ambiguity in the representation of numbers, always specify the base used to
represent the number, except for base 10.
Example :
X = 101 in base 2 is different from X = 101 in base 10.
Therefore, X = 101 in base 2 will be expressed as X=(101)2
3
The division is repeated until q is less than B.
The rest obtained in the division operation as well as the last value of q are noted from right to
left in the expression of the number.
Example
Let the integer X= 44 be expressed in base 10. To express X in base 3, divide successively by 3 :
44 = 14*3 + 2
14 = 4*3 + 2
4 = 1*3 + 1
Examples
1) Consider the number X expressed in base 7, X = (3425)7
The decimal value of X is:
𝑿 = 𝟓. 𝟕𝟎 + 𝟐. 𝟕𝟏 + 𝟒. 𝟕𝟐 + 𝟑. 𝟕𝟑 , therefore X=1244 in base 10
Knowing that each binary symbol requires one bit (0 or 1), a binary number is therefore a collection of
bits. Knowing also that the number 8 is a puissance 3 of 2 and that the number 16 is a puissance 4 of 2,
each octal digit corresponds to 3 bits and each hexadecimal digit to 4 bits.
4
Binary 000 001 010 011 100 101 110 111
Octal 0 1 2 3 4 5 6 7
Examples :
Note:
The missing bits on the left are filled with zeros.
Note :
The base 16 digits are:{0,1,2,3,4,5,6,7,8,9, 𝐴, 𝐵, 𝐶, 𝐷, 𝐸, 𝐹}
Example :
Let the integer X be expressed in binary: X=(1101111011)2
X is converted to hexadecimal by grouping four bits from right to left, as follows:
5
Note:
Direct conversion from a Base B to a Base K is possible if one of the two bases is an integer power
of the other (e.g. B=3, K=9) and vice versa.
1.2.3. Arithmetic
Classical arithmetic operations for other bases are performed in the same way as in decimal. In
the following, we will present binary arithmetic operations as illustrative examples. The details will be
explained in the course work.
The binary addition of two numbers is processed bit by bit from right to left, carrying forward the carry
over.
Example :
Let be the two numbers X = (1101101)2 and Y = (10101011)2
10111101111101
+ X+Y = (100011000)2
1 01 0 1 0 11
10 00 1 1 0 00
The binary subtraction of two numbers is carried out bit by bit from right to left, carrying forward the
carries
6
Note: more details will be provided in the coursework.
Example :
11010
x 1010
= 00000
+ 11010 .
+ 00000 . .
+11010 . . .
= 100000100
Note :
The product of two positive numbers is always greater than the multiplied numbers,
which poses a problem for the internal representation of numbers (size and capacity)
Binary division is a fairly complex operation, generally using the same principle as decimal
division (division by subtraction).
The development of arithmetic in the different bases will be explained in the supervised work
sessions..
7
1.3. The negative integers
In binary calculation, positive integers are represented only as 0 and 1. The negative sign
preceding integer values poses a problem for their machine representation.
Several methods are used to represent negative numbers in a computer, including: sign and absolute
value representation (SAV), complement to 1 (CP1) and complement to 2 (CP2).
Example1 :
On 4 bits we will have 16 integers: (-7,-6,-5,-4,-3,-2,-1,-0,+1,+1,+2,+3,+4,+5,+6,+7).
Note : for a number encoded on an n-bit word, we will actually have 2n-1 different numbers (zero has
two codes)
Example2 :
The integer X=-20 will be coded in SAV on at least 6 bits as follows: 20 =(10100)2
X will be coded by: 110100.
Example3 :
The integer number X=+ 20 will be coded in 6 bits SAV as follows:
20 = (10100)2
X will be coded as: 010100.
Example4 :
The integer number X=-20 will be coded in 8 bits SAV as follows:
20 =(10100)2
X will be coded as: 10010100.
Note:
In SAV, addition and subtraction operations are complicated because the sign bit has to be handled
separately. This method is not used by computer manufacturers for addition and subtraction
operations. SAV arithmetic applications will be covered in more detail in the supervised classes.
8
1.3.2. Representation of negative integers in 1's complement (CP1)
1.3.2.1. Principle:
A negative integer is obtained in 1's complement (logical complement) by replacing each 0 bit
by 1 and vice versa, in the binary code of the positive number. The highest bit in the number code is
reserved for the sign (1 for the '-' sign and 0 for the '+' sign).
Example:
Consider the integer X = - 5 coded on 4 bits;
We have: +5 = (0101)2 in binary (the highest bit is a sign bit, 0 for a positive sign).
The CP1 (+5) = - 5, so X = 1010 inCP1.
1.3.2.1. Properties:
In 1's complement,CP1(X) is the symmetric of (X).
The integers coded on n bits in CP1 will be numbers of 2n-1 positive number and 2n-1 negative
number. The range of representation of an integer X coded on n bits is:
– (𝟐𝒏−𝟏 − 𝟏) ≤ 𝑿 ≤ +(𝟐𝒏−𝟏 − 𝟏) .
Knowing that on n bits we have 2n representations, and from 0 to 2n-1-1 we have 2n-1 numbers. So
zero counts 2 times (+0) and (-0).
1.3.2.1. ARITHMETICS
Addition in CP1:
Principle :
In addition, a carry generated by the sign bit must be added to the result obtained because the
complements are added together, including the sign bit (carry). A necessary condition for adding
the carry is that a carry must also be generated by the bit just before the sign one.
If a carry is generated exclusively by the sign bits or by the bit just before the sign, addition cannot
be performed. An overflow error is declared.
Example1:
Consider the two integers X = 7 and Y = 6,
We want to perform the X-Y operation on 4 bits in CP1
)6-( + )7( = 6-7 thus, 7- 6 = 7 + CP1(6).
7= (0111)2 and 6= (0110)2 with CP1(6) = 1001
1
So, 01 11 1 1
+
1 0 0 1
9
Example2 :
Let be the two integers X= 7 and Y = 6, We want to perform the X+Y operation on 4 bits in CP1
7= (0111)2 et 6= (0110)2
1
So , 0 11 1 1
+
0 110
= 1 1 0 1 Wrong result
Note: In CP1, subtracting a number is reduced to adding its complement to 1 (the subtraction circuit
is useless). In addition, CP1 does not handle the sign bit separately.
1.3.2.1. Principle :
The 2's complement (arithmetic complement) of a negative integer is obtained by adding +1 to its
CP1 representation.
This representation gives an additional configuration because the zero will have a single
representation.
Example:
Let the integer X = - 5 be coded on 4bits;
We have : X = 1010 in CP1.
The CP2(+5)= CP1(+5) +1, thus X = 1011 in CP2.
1.3.2.2. Properties
The value of a number represented in CP2 is the same as reading a binary number Xn-1Xn-2…X0 as
follows:
𝑿 = 𝟐𝒏−𝟐 𝑿𝒏−𝟐 + ⋯ + 𝟐𝟏 𝑿𝟏 + 𝟐° 𝑿𝟎 − 𝟐𝒏−𝟏 𝑿𝒏−𝟏
Thus, 𝑿 = (∑𝒏−𝟐 𝒊
𝒊=𝟎 𝑿𝒊 𝟐 ) - 𝑿𝒏−𝟏 𝟐
𝒏−𝟏
11
1.3.2.2. ARITHMETICS
Addition in CP2
Principle :
In CP2 addition, a carry generated by the sign bit will be ignored. A necessary condition for
accepting the result thus obtained is that a carry must also be generated by the bit just before sign.
If a carry is generated exclusively by the sign bits or by the bit just before the sign, addition cannot
be performed.
Example1 :
Let the two integers X= 7 and Y = 6
We want to perform the operation X-Y on 4 bits in CP2
7- 6 = (7)+(-6) thus, 7- 6 = 7 + CP2(6).
7= (0111)2 et 6= (0110)2 with CP1(6) = 1001 thus, CP2(6) = 1010
1
So, 0 11 1 1
+
1 010
= 10 001
A carry is generated by the sign bit and the bit before the sign one. It will be ignored and the result is
correct (7 – 6 = 1).
Example2 :
Given the two integers X= 7 and Y = 6,
We want to perform the operation X+Y on 4 bits in CP2
7= (0111)2 and 6= (0110)2
1
So, 0 11 1 1
+
0 1 1 0
= 1 1 0 1 Incorrect result
11
Note :
Subtracting a number is the same as adding its opposite, i.e. its 2's complement.
Multiplying two numbers involves multiplying the absolute values of the 2 numbers and taking
the opposite of the result if the numbers have different signs.
To divide, go through the division of absolute values and reposition the signs of the quotient
and rest if necessary.
Computers only manipulate bits, so we need to define a representation of decimal numbers that
is suitable for calculations. In addition, the space available for storing a number on a machine is
limited, which limits the precision of calculations.
The basic idea for the representation of decimal numbers is to define the location of a comma separating
the integer part from the decimal part and to consider that the digits to the right of the comma correspond
to the negative powers of the base (as for decimals).
Example :
12
1.4.1.2. Decimal to base B conversion
To transform a fractional decimal number into base B, the integer part is transformed using the
same principle as for whole numbers. The fractional part is obtained by successive multiplication of the
fractional part by the base B. The integer part resulting from the multiplication is noted in each operation.
The multiplication process is repeated until the fractional part disappears or a period of digits appears.
Example :
0,125 =(0,001)2
1.4.1.3. Arithmetic
Fixed-point arithmetic operations in base B are performed in the same way as in base 10.
Note :
More details will be given in the supervised classes..
1.4.2.1. Principle :
Floating point representation consists of representing real numbers in the following form:
X =± M.BE , with:
B : Base (2, 8, 10, 16, …)
M : Mantissa (a purely fractional number)
E : Exponent (an integer number)
The mantissa is standardized (it has the maximum number of significant digits), so:
(𝟎, 𝟏)𝟐 ≤ |𝑴| < (𝟏)𝟐 thus, (𝟎, 𝟓)𝟏𝟎 ≤ |𝑴| < (𝟏)𝟏𝟎
13
Exponent and mantissa must be able to represent positive and negative numbers. They could
be coded as SAV, CP1 or CP2, often M is coded in SAV form, E is sign less but shifted
(Biased).
The internal representation of a real number normalized to n bits will have the following form:
SM E M
Mantissa sign Exponent Mantissa
Principle:
E : is an exponent coded on 8 bits, the exponent is shifted by +127 because it will be represented
without a sign on the 8 bits (Es = E + 127)
S Es M
Sign Exponent shifted Mantissa
One (1) sign bit, 8 bits for the exponent and 23 bits for the pseudo mantissa
Description:
1) The highest bit is a sign bit, representing the sign of the mantissa (1 for a negative sign and 0
for a positive sign).
2) The 8-bit exponent is shifted by +127 to represent positive and negative powers. The exponent
range is :– (𝟐𝟖−𝟏 ) ≤ 𝑬 ≤ +(𝟐𝟖−𝟏 − 𝟏) with , – 𝟏𝟐𝟕 ≤ 𝑬 ≤ +𝟏𝟐𝟕
The shifted exponent will be represented on 8 unsigned bits and will be in the range:
0 ≤ 𝑬𝒔 ≤ 𝟐𝟓𝟓 .
The accepted values for Ed are the interval𝟏 ≤ 𝑬𝒔 ≤ 𝟐𝟓𝟒. The values zero and 255 will be
reserved for other purposes.
14
Similarly, the accepted values for E are : −𝟏𝟐𝟔 ≤ 𝑬𝒔 ≤ +𝟏𝟐𝟕. Values -127 and +128 will be
reserved for other purposes.
The pseudo-mantissa is the fractional part, occupying the lowest 23 bits in the internal
representation.
Example :
Representation of the number X= 25.127 in IEEE-754 floating point in single precision:
1) Set X in the Form 𝑿 = ∓𝟏, 𝑴. 𝟐𝑬
25 = (11001)2 , 0.125 =(0,001)2
25,125 = +1,1001001 . 24
2) The pseudo-mantisse : M=(0,1001001)2
3) The biased exponent : Es = 4+127= 131 ; 131 =(10000011)2
4) le bit de signe = 0
0 10000011 10010010000000000000000
S Es M
Note :
The internal representation of the real number can be expressed in hexadecimal, octal, etc...
In the previous example, if we proceed by grouping 4 bits from right to left, then replace the
groupings by their hexadecimal equivalents, we obtain the internal hexadecimal
representation of the real number: X= 41C90000
Remark: Floating-point real arithmetic and more detailed applications of the IEEE-754 standard will
be covered in supervised classes.
The table below summarises the ranges of real number values represented in IEEE-754 single precision
standards.
15
Shifted
Signe Exponent Mantisse Value
Exponent
0 0 -127 0 Zéro
1 0 -127 0 Zéro
Denormalized number
0 0 -127 ≠ 0
𝑿 = +𝟎, 𝑴. 𝟐−𝟏𝟐𝟕
Denormalized number
1 0 -127 ≠ 0
𝑿 = −𝟎, 𝑴. 𝟐−𝟏𝟐𝟕
Normalized number
0 1 ≤ Es ≤ 254 -126 ≤ E ≤ +127 Any
𝑿 = +𝟏, 𝑴. 𝟐−𝑬
Normalized number
1 1 ≤ Es ≤ 254 -126 ≤ E ≤ +127 Any
𝑿 = −𝟏, 𝑴. 𝟐−𝑬
0 255 128 0 +∞
1 255 128 0 -∞
0 255 128 ≠ 0 NaN
1 255 128 ≠ 0 NaN
16