0% found this document useful (0 votes)
7 views16 pages

MS1-chap1 - Part1

The document outlines the curriculum for the Machine Structure course at Abdelhamid Mehri University, focusing on the codification and representation of numbers, including binary and machine code. It covers the representation of positive and negative integers in various bases, arithmetic operations in binary, and methods for representing negative integers. The course aims to provide students with a foundational understanding of computer architecture and number representation essential for their studies in New Technologies.

Uploaded by

Mennech
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views16 pages

MS1-chap1 - Part1

The document outlines the curriculum for the Machine Structure course at Abdelhamid Mehri University, focusing on the codification and representation of numbers, including binary and machine code. It covers the representation of positive and negative integers in various bases, arithmetic operations in binary, and methods for representing negative integers. The course aims to provide students with a foundational understanding of computer architecture and number representation essential for their studies in New Technologies.

Uploaded by

Mennech
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

Abdelhamid Mehri University - Constantine 2

2024-2025. Term 1

Machine Structure

Chapitre 01 - part-1 Codification and representation of numbers


- part-2 α-Numeric coding
- part-3 Boolean Algebra

Teaching staff

Name Grade Faculty/Institute E-mail address


Bahri Mohamed redha MCB New Technologies [email protected]
Boussebough Imen MCB New Technologies

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.

1.2. Positive integers :


The computer calculates in binary, and only the symbols 0 and 1 are used to represent and
manipulate numbers. In addition, the size of the numbers manipulated is limited, so storage space is
limited in size, which limits the computer's ability to express numbers.

1.2.1. Representation of positive integers in a base B


Just as in decimal we use ten digits to represent numbers, in base B (B is an integer and B ≥ 2)
we use B digits to represent numbers:
Let be a base B whose set of digits is: E={𝑋0 , 𝑋1 , 𝑋3 , … … … … … . 𝑋𝑛−1 }

Each number X expressed in base B will be represented by a concatenation of the symbols 𝑋𝑖 in set E.

Examples :

In base 10: X = 19372 , E={0,1,2,3,4,5,6,7,8,9}; The number X is represented by the digits


1,9,3,7 and 2 in base 10.
In base 2: X = 10111, E={0,1}; The number X is represented by the digits 1 and 0.

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

1.2.1.1. Representation of a positive integer in a base


Let X be a positive integer and let B be a base (Bϵ N and B ≥ 2).
To obtain the representation of X in the base B we apply the principle of Euclidean division :
X = q.B + r.

Each time, q is divided by B and the rest is noted.

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

The last rest is 1, 1 is less than 3, so we stop the division process.


Thus the decimal number 44 expressed in base 10 will be expressed (1122) in base 3.

1.2.1.1. Decimal value of a number expressed in base B


The decimal value of a number X expressed in base B is obtained by multiplying each digit of
base B, from right to left in the representation of X, by an increasing integer power (starting with zero)
of the base. The values obtained in the calculation are added together.

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

2) Consider the number X expressed in base 2, X = (1101)2


The decimal value of X is:
𝑿 = 𝟏. 𝟐𝟎 + 𝟎. 𝟐𝟏 + 𝟏. 𝟐𝟐 + 𝟏. 𝟐𝟑 , therefore X=13 in base 10

1.2.2 The classical bases :


Whole numbers are generally coded using a number of traditional bases: base 2 (binary), base
8 (octal), base 10 (decimal) and base 16 (hexadecimal).
In this section we present the conversion of binary numbers to octal and hexadecimal, as this plays a
key role in digital systems.

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.

1.2.2.1. Binary conversion Octal


The conversion from binary to octal is done by grouping 3 bits from right to left in the binary
representation of the number, each grouping being replaced by the equivalent digit in octal base.

4
Binary 000 001 010 011 100 101 110 111
Octal 0 1 2 3 4 5 6 7

Examples :

Let the integer X be expressed in binary form X = (1101001)2

X is converted to octal by grouping three bits from right to left, as follows:

X = 001 101 001 thus X =(151)8


1 5 1

Note:
The missing bits on the left are filled with zeros.

1.2.2.2. Binary hexadecimal conversion


The conversion from binary to hexadecimal is done by grouping 4 bits from right to left, each
collection being replaced by the equivalent digit in hexadecimal base.

Binary 0000 0001 0010 0011 0100 0101 0110 0111


Hexadécimal 0 1 2 3 4 5 6 7
Binary 1000 1001 1010 1011 1100 1101 1110 1111
Hexadécimal 8 9 A B C D E F

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:

X=0011 0111 1011 thus X= (37B) 16


3 7 B

The missing bits on the left are filled with zeros.

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.

1.2.3.1. Binary addition :


Two binary bits are added according to the following specification:

Bit1 Bit2 Carry Sum


0 + 0 = 0 0
0 + 1 = 0 1
1 + 0 = 0 1
1 + 1 = 1 0

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

The addition operation is performed in the same way as in base 10

10111101111101

+ X+Y = (100011000)2
1 01 0 1 0 11

10 00 1 1 0 00

1.2.3.2. binary subtraction :


The subtraction of two binary bits is carried out according to the following specification :

Bit1 Bit2 Carry Diff


0 - 0 = 0 0
0 - 1 = 1 1
1 - 0 = 0 1
1 - 1 = 0 0

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.

1.2.3.3. Binary multiplication :


The multiplication of two binary bits is realised according to the following specification :

Bit1 Bit2 Result


0 X 0 = 0
0 X 1 = 0
1 X 0 = 0
1 X 1 = 1

Example :

Let be the two numbers X= (110 10)2 et Y= (1010)2

The X * Y multiplication operation is performed in the same way as in base 10

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).

1.3.1. Representation of negative integers in SAV (Sign and absolute value)


1.3.1.1. Principle
Integers in SAV are coded in binary by ± absolute value, with the highest bit of the number
represented reserved for the sign (1 for the '-' sign and 0 for the '+' sign).
An integer coded on n bits will have an absolute value V : 𝟎 ≤ 𝑽 ≤ 𝟐𝒏 − 𝟏
1.3.1.2. Property
Given an integer X coded in n-bit SAV, the range of the representation of X is: – (𝟐𝒏−𝟏 − 𝟏) ≤
𝒏−𝟏
𝑿 ≤ +(𝟐 − 𝟏).
Knowing that for n bits we have 2n representations, and from 0 to 2n-1-1 we have 2n-1 numbers. Thus,
zero counts 2 times (+0) and (-0).
The zero then has two representations: (-(2n-1-1),……-1,-0,+0,1,2,…,(2n-1-1)).

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).

Note: CP1 representation is easy to be produced electronically.

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

= 10 0 0 0 a carry is generated by the bit and the pre-sign bit


+1

= 0 0 0 1 the result is correct 7 – 6 = 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

A carry is generated only by the bit before the sign.


The addition is incorrect (7 + 6 = 13, the signed number +13 requires 5 bits for coding. An overflow
must be signalled in this case.).

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. 2's complement representation (CP2)

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 range of representation of an integer X coded on n bits in CP2 is : – (𝟐𝒏−𝟏 ) ≤


𝑿 ≤ +(𝟐𝒏−𝟏 − 𝟏)

On n bits we have : X+CP2(X)=2n (hence the name 2's complement)

The value of a number represented in CP2 is the same as reading a binary number Xn-1Xn-2…X0 as
follows:
𝑿 = 𝟐𝒏−𝟐 𝑿𝒏−𝟐 + ⋯ + 𝟐𝟏 𝑿𝟏 + 𝟐° 𝑿𝟎 − 𝟐𝒏−𝟏 𝑿𝒏−𝟏

Thus, 𝑿 = (∑𝒏−𝟐 𝒊
𝒊=𝟎 𝑿𝒊 𝟐 ) - 𝑿𝒏−𝟏 𝟐
𝒏−𝟏

The CP2 (CP2(X)) = X for any integer value X.

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

A carry is generated only by the bit before the sign.


The addition is incorrect (7 + 6 = 13, the signed number +13 requires 5 bits for coding and representation.
An overflow must be signalled in this case).

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.

1.4. The real numbers

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).

1.4.1. Fixed-point representation of real numbers :


The aim of fractional calculation is to achieve maximum precision in writing fractional numbers.
The position of the decimal point in the number determines this precision. Unfortunately, in a computer
the size of the representation is limited, so managing the position of the decimal point poses a real
problem.

1.4.1.1. B base to decimal base conversion


In the representation of a number or fixed point, a position is chosen in the digits of the number
to separate the fractional part to the right of the chosen position, and the integer part from the chosen
position to the left.
The fractional part is converted by successive multiplications by negative and decreasing powers of
the base B used, starting with (-1).The integer part is obtained using the principle of integers.
So, to code a real number in n positions, we can, for example, define a comma after the K least significant
digits,

For X= (an-K-1…a1a0,a-1 …a1-k a-k)B


𝑛−𝑘−1
The decimal value of X is given by the formula: X = ∑𝑖=−𝑘 𝑎𝑘 2𝑘

Example :

Let the real number x be coded in fixed-point binary: X = (1101 , 01)2


The decimal value of x is obtained as follows:
X= (1* 2-2 ) + (0* 2-1 ) + (1* 20 ) + (0* 21 ) + (1* 22 ) + (1* 23)
Thus, X= 0.25 + 0 + 1 + 4 + 8.
Hence X = 13.25.

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 :

X=7,125 we want to express X in binary base:

Conversion of the integer part of X to base 2: 7=(111)2

Converting the fractional part of X to base 2:

0,125 x 2 = 0,25 = 0 + 0,25


0.25 x 2 = 0,5 = 0 + 0,5
0,5 x 2 = 1,0 = 1 + 0,0

0,125 =(0,001)2

Thus : 7,125 =(111,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. Floating point representation of real numbers :


Since it is difficult to manage the position of the fixed point, floating point
representation is generally adopted.

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

1.4.2.2.Case study: representation of floating-point real numbers according to the


IEEE-754 standard in single precision.

In order to standardize the representation of numbers in floating-point format, several standards


have been proposed.
In the following, we will look at the IEEE-754 standard established by the IEEE (Institute
of Electrical and Electronics Engineers) committee, in single precision on 32 bits.

Principle:

In this standard, a floating-point number X is written in the form 𝑿 = ∓𝟏, 𝑴. 𝟐𝑬 , where :


M : represents the pseudo mantises because the integer 1 is not represented. The mantises is coded
on 23 bits (corresponding to the negative powers from 2-1 to 2-23).

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)

A sign bit. According to the following diagram:

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

So on 32 bit in IEEE-754 standar, the number X=25,125 will be represented internally by :

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

You might also like