31/10/2024
Computer architecture
1st year of Computer Engineering cycle
Dr. Soraya CHERIGUENE
2024 - 2025
1
31/10/2024
Chapter 2
Information representation
2
31/10/2024
Plan du chapitre
3
Introduction
Decimal representation
Representation of integers
Representation of real numbers
Character Representation
3
31/10/2024
4 Introduction
Before processing a quantity, it needs to be converted into a digital image that
represents the magnitude and can be manipulated by electronics.
Information encoding involves establishing a correspondence between the external
(usual) representation of the information (text, image, etc.) and its internal
representation in the machine, which is always a sequence of bits called a code word
(digital image of the quantity).
Example of encoding:
encoding of the character
string ”Ada b”
4
31/10/2024
5 Decimal representation : Binary Coded Decimal
The information processed by the computer is not always converted according to the
binary numeral system.
In fact, this information can be manipulated in binary-coded decimal form, meaning that
codes (binary) are associated with decimal numbers without necessarily going through
the traditional decimal → binary conversion.
A certain number of codes are defined for this purpose :
• Gray Code
• BCD Code(binary coded decimal)
• EXCESS3
5
31/10/2024
6 Decimal representation: Pure Binary
Pure binary is also referred to as natural binary. This encoding has already been
discussed in the context of Chapter 1 dealing with numeral systems.
Indeed, in this encoding, we associate each positive integer with its corresponding value
according to the binary numeral system.
Thus, with n bits, we can encode values ranging from [0 et 2n-1].
Example :
Using 6 bits : (35)10 = (100011)2
Please note that the value (35)10 is not representable with 5 bits. Remember that to
encode a value with n bits, it must be within the range [0 et 2n-1], in our case
between[0 et 25-1] = [0 et 31].
6
31/10/2024
7 Decimal representation : GRAY Code
The fundamental property of Gray code, also known as reflected binary code, is that only one
bit changes state when transitioning from one term to the next.
Here is one of the methods to calculate the Gray code: Given a number B (𝐵 𝐵 … 𝐵 ) in
pure binary, to obtain its equivalent G(𝐺 𝐺 … 𝐺 ) in Gray code, simply perform the following
operations:
𝐺 =𝐵
𝐺 =𝐵 ⊕𝐵 ; (where ⊕ represents the exclusive OR (XOR) function).
Example : Consider the binary code: b3 b2 b1 b0 = 1 1 1 0
Gray Code : g3 g2 g1 g0
g3 = b3 = 1 g1 = b2 ⊕ b1 = 1 ⊕ 1 = 0
g2 = b3 ⊕ b2 = 1 ⊕ 1 = 0 g0 = b1 ⊕ b0 = 1 ⊕ 0 = 1
Therefore, the corresponding Gray code is: 1 0 0 1
7
31/10/2024
8 Decimal representation : GRAY Code
Given a Gray code G( … ). to obtain its equivalent binary number B (
), simply perform the following operations :
; (where represents the exclusive OR (XOR) function).
Example : Consider the Gray code: g3 g2 g1 g0 = 1 0 0 1
Binary code b3 b2 b1 b0 :
b 3 = g3 = 1 b 1 = b 2 ⊕ g1 = 1 ⊕ 0 = 1
b 2 = b 3 ⊕ g2 = 1 ⊕ 0 = 1 b 0 = b 1 ⊕ g0 = 1 ⊕ 1 = 0
Therefore, the corresponding binary code is : 1 1 1 0
8
31/10/2024
9 Decimal representation : BCD Code
Binary Coded Decimal (BCD) is the most commonly used code. Its
principle is based on associating a binary code with each decimal
digit.
The principle involves splitting into 4 bits and replacing each
decimal digit with its corresponding binary value. Each binary
element in a code word has a weight just like in natural binary.
There are unused binary configurations. Indeed, the number of
configurations that can be represented with 4 digits is 16, so we
deduce that there are 6 unused configurations as shown in the
table :
9
31/10/2024
10 Decimal representation : BCD Code
Example :
10
31/10/2024
11 Decimal representation : EXCESS3
Code excédent 3 (EXCESS3 ; BCD+3. EX3 ):
This code closely resembles the code. Its
principle is based on associating with each
decimal digit its binary equivalent added by 3.
Example:
11
31/10/2024
12 Representation of integers
There are two types of integers :
Unsigned integers (positive)
Signed integers (positive or negative)
Problem : How to indicate to the machine whether a number is negative or positive?
There are 3 methods to represent negative numbers :
Sign/magnitude
One's complement (restricted complement)
Two's complement (true complement)
12
31/10/2024
13 Representation of integers : Unsigned
Natural numbers (non-negative integers) are encoded using a fixed number of octets
(bytes) (1 octet = 8 bits). We typically encounter encodings using 1, 2, 4 octets, and less
commonly 8 octets (64 bits).
A coding using n octets can represent all natural numbers between 0 and -1.
Example : with one octet (8 bits), we can represent (encode) numbers within the range:
[0, -1] = [0,255]
13
31/10/2024
14 Representation of integers : Signed
1. Sign-magnitude representation
With n bits, the nth bit is reserved for the sign.
• 1 : negative sign (-)
• 0 : positif sign (+) Sign magnitude
The remaining n-1 bits are used for representing the absolute value of the number to be
encoded.
Example 01: With 8 bits
14
31/10/2024
15 Representation of integers : Signed
1. Sign-magnitude representation
Capacity: If we work with 3 bits
•The values range from-3 and +3
sign Mag valeur -3 ≤ N ≤ +3
0 00 +0 - ( 4-1 ) ≤ N ≤ + (4 -1 )
0 01 +1 -(22 -1) ≤ N ≤ +(22-1 )
0 10 +2 -(2 (3 -1) -1) ≤ N ≤ +(2 (3 -1) -1 )
0 11 +3
1 00 -0
1 01 -1
1 10 -2
1 11 -3
15
31/10/2024
16 Representation of integers : Signed
1. Sign-magnitude representation
A coding using n bits can encode all integers belonging to the range: [-(2 -1), + (2 -1)]
-(2 (n -1) -1) ≤ N ≤ +(2 (n -1) -1 )
Example:
If n=5, N is between (-15) et (+15).
Remark : This method has the following drawbacks::
0 has two representations 0000 and 1000 on 4 bits.
Arithmetic operations are complicated due to the sign bit
that must be handled separately.
16
31/10/2024
17 Representation of integers : Signed
2. One's complement (restricted complement)
To obtain the one's complement (1’s C) of a binary number :
The first bit is reserved for the sign.
If the number is positive, it retains its format, (encoded as in Sign-magnitude coding)
If the number is negative, it is represented by the one's complement (1’s C), where each bit
is inverted (0 becomes 1 and 1 becomes 0).
Example :
17
31/10/2024
18 Representation of integers : Signed
2. One's complement (restricted complement)
Remark :
The one's complement of the one's complement of a number is equal to the number itself.
1’s C ( 1’s C ( N ) ) = N
Example :
What is the decimal value represented by the value 101010 in one's complement on 6 bits?
The most significant bit indicates that it is a negative number.
Value = 1's C(101010)= (110101)SMa= - (10101)2= - (21)10
18
31/10/2024
19 Representation of integers : Signed
2. One's complement (restricted complement)
Capacity: with 3 bits :
•The values range from-3 and +3
1’s C binary Decimal
Value value value -3 ≤ N ≤ +3
000 000 +0 - ( 4-1 ) ≤ N ≤ + (4 -1 )
001 001 +1 -(22 -1) ≤ N ≤ +(22-1 )
010 010 +2
-(2 (3 -1) -1) ≤ N ≤ +(2 (3 -1) -1 )
011 011 +3
111 -000 -0 If we work with n bits, the range of values that can
110 -001 -1
be represented in 1's C is:
101 -010 -2
100 -011 -3 -(2 (n -1) -1) ≤ N ≤ +(2 (n -1) -1 )
19
31/10/2024
20 Representation of integers : Signed
2. One's complement (restricted complement)
Arithmetic operation:
In 1's C, subtraction of a number is reduced to adding its complement.
Example : -13 -11 (-13)1's C + (-11)1’s C
It is based on the following principle:
If no carry is generated by the sign bit, the result is correct and is represented in 1's
complement.
Otherwise, it will be removed and added to the result of the operation, which is
represented in 1's complement.
20
31/10/2024
21 Representation of integers : Signed
2. One's complement (restricted complement)
Arithmetic operation:
21
31/10/2024
22 Representation of integers : Signed
3. Two's complement (true complement)
The two's complement (2’s C) is the most widely used representation in binary arithmetic and
therefore in computers to encode integers.
To find the two's complement of a negative number: you need to traverse the bits of this number
from the least significant bit and keep all the bits before the first 1, then invert the remaining bits
that come after. The most significant bit (sign bit) will not change.
22
31/10/2024
23 Representation of integers : Signed
3. Two's complement (true complement)
Another method is to add 1 to the one's complement of the number.
1's C(N)+1 = 2's C(N)
where N is an integer.
A positive number is represented in the same way as in sign/ magnitude coding.
Example:
23
31/10/2024
24 Representation of integers : Signed
3. Two's complement (true complement)
Remarks :
In this representation, the most significant bit indicates the sign (0: positive, 1: negative).
The two's complement of the two's complement of a number is equal to the number itself.
2's C(2's C(N))= N
Example : What is the decimal value represented by the value 101010 in two's complement on 6
bits?
The most significant bit indicates that it is a negative number.
Valeur = 2's C(101010) = 1's C (101010) + 1= 110101+1= (110110)SMA = - (10110)2= - (22)
24
31/10/2024
25 Representation of integers : Signed
3. Two's complement (true complement)
Capacity: with 3 bits :
•The values range from-4 and +3
2’s C binary Decimal
Value value value -4 ≤ N ≤ +3
000 000 +0 - ( 4 ) ≤ N ≤ + (4 -1 )
001 001 +1 -(22 ) ≤ N ≤ +(22-1 )
010 010 +2 -(2 (3 -1) ) ≤ N ≤ +(2 (3 -1) -1 )
011 011 +3
111 -001 -1 If we work with n bits, the range of values that can
110 -010 -2
be represented in 1's C is:
101 -011 -3
100 -100 -4 -(2 (n -1) ) ≤ N ≤ +(2 (n -1) -1 )
25
31/10/2024
26 Representation of integers : Signed
3. Two's complement (true complement)
Arithmetic operation:
In 2's C, subtraction of a number is reduced to adding its complement.
Example : -13 -11 (-13)2's C + (-11)2's C
It is based on the following principle :
If there is a carry generated by the sign bit, it is ignored, and the result is in 2's
complement.
Otherwise, the result is correct and is represented in 2's C.
26
31/10/2024
27 Representation of integers : Signed
3. Two's complement (true complement)
Arithmetic operation:
27
31/10/2024
28 Representation of integers : Signed
Overflow :
It is said that there is an overflow if the number of bits used is insufficient to contain the result.
Oveflow occurs only if both numbers have the same sign.
There is never an overflow if the two numbers have opposite signs.
Example 1 : For 4-bit representation
0111+0001 = 1000 WRONG
1000 in two’s complement is -8, not +8
Example 2: For 8-bit representation
01000000 = +64 10000001 = -127
01000001 = +65 10000001 = -127
X
10000001 = -127 100000010 = +2X
Discard carry
The overflow Sign bit of the result different than the sign bit of the two added numbers.
28
31/10/2024
31 Representation of integers : Signed
Summary for addition in "complement":
Two numbers of opposite signs
• The result is representable within the fixed number of bits, no overflow;
• If there is a carry, the result is a positive number.
o We add the carry to obtain its value in 1's complement.
o We disregard it in 2's complement.
Two numbers with a positive sign
• Overflow occurs when the sign bit of the result is 1;
Two numbers with a negative sign
• There is a carry since both sign bits are 1.
• We add the carry to obtain its value in 1’s C and We disregard it in 2's C
o A 0 for the sign bit indicates an overflow.
o A 1 for the sign bit means the result is correct.
29
31/10/2024
32 Representation of real numbers
A real number consists of two parts: the integer part and the fractional part (the two parts
are separated by a comma).
Problem : how to indicate to the machine the position of the comma?
→ There are two methods to represent real numbers:
Fixed-point: The position of the comma is fixed.
Floating-point: the position of the comma changes (dynamic).
30
31/10/2024
33 Representation of real numbers: Fixed-point
In this representation, the integer part is represented using n bits, and the fractional part
is represented using p bits, plus one bit is used for the sign..
Example : In an 8-bits representation such as:
1 bit represents the sign, 4 bits represent the integer part, and 3 bits represent the decimal
part, we have:
(-1011,11)2 (11011110)in the machine
31
31/10/2024
34 Representation of real numbers: Floating-point
For a floating-point number, we associate two sets of values:
The first represents the significant digits of the number, which is the mantissa (M).
The second indicates the power to which the base (B) is raised, which is the exponent (e).
The most obvious and concise way to represent a floating-point number is therefore to
use a signed exponent and mantissa.
Each real number can be written in the following way:
N = ±M x Be
Examples:
21,76 = 21,76 x100 = 2176 x 10-2…
-(110,101)2 = -(0,110101)2 x 2+3 = -(0,0110101)2 x 2+4 …
(0,00101)2 = (0,101)2 x 2-2
32
31/10/2024
35 Representation of real numbers: Floating-point
It can be noted that, in principle, a floating-point representation is not necessarily unique. Therefore, we
need to represent them in a normalisation form so that the representation does not vary from one
hardware to another. The normalisation representation of numbers is in the form:
1,mantissa × 2exponent
Therefore, it is not necessary to store the 1 to the left of the decimal point. This way, we save a precious
bit. Called ‘implied bit’
In this n-bit representation:
MS : mantissa sign, encoded in 1 bit with the most significant bit: sign – : 1; sign +: 0.
M: Normalized mantissa: the decimal point is placed after the most significant bit that is 1; it is
encoded in q bits.
BE: stored or biased exponent (to ensure positivity) is represented in p bits.
MS BE M
1 bit p bits q bits
33
31/10/2024
36 Representation of real numbers: Floating-point
Representation of a biased exponent :
For an integer number, the range of values can be represented using p bits :
-(2 (p -1) – 1) ≤ N ≤ 2 (p -1) - 1
If we add the value (2 (p -1) – 1) to both sides of this inequality :
- (2 (p -1) – 1) + (2 (p -1) – 1) ≤ N + (2 (p -1) – 1) ≤ 2 (p -1) – 1 + (2 (p -1) – 1)
0 ≤ N + (2 (p -1) – 1) ≤ 2 p – 2
•Let's define: N’= N + (2 (p -1) – 1) So : 0 ≤ N’ ≤ 2 p
•In this case, we obtain positive values. The value (2 (p -1) – 1) is called the bias.
•With the biased exponent, we have transformed negative exponents into positive exponents by
adding the value (2 (p -1) – 1) to the exponent .
Biased Exponent = Real Exponent + Bias
34
31/10/2024
37 Representation of real numbers: Floating-point
We want to represent the numbers (expressed in octal) ( 0,015)8 et (-15, 01)8 in floating point on a
machine with the following format :
MS BE M
1 bit 4 bits 11 bits
(0,015)8=(0,000001101)2= 1,101 * 2-6
Mantissa sign : positif ( 0)
Normalised mantissa: 1,101
Exponent = -6
Calcul of the biais : b= 24-1 -1= 7 0 0001 10100000000
Biased exponent= -6 + 7 = +1 = ( 0001)2 1 bit 4 bits 11 bits
35
31/10/2024
38 Representation of real numbers: Floating-point
- (15,01)8 = - (001101,000001)2= - 1,101000001 * 23
mantissa sign : negative ( 1)
Normalised mantissa : 1,101000001
Exponent = 3 ,
Calcul of the biais : b= 24-1 -1= 7
Biased exponent= 3 + 7 = +10 = ( 1010)2
1 1010 10100000100
1 bit 4 bits 11 bits
36
31/10/2024
39 Representation of real numbers: Floating-point
IEEE 754 Standard
This representation of real numbers is, in fact, an international standard that is widely
recognized and used by the majority of computer manufacturers today.
This standard defines three formats for floating-point numbers:
Single precision on 32 bits
Double precision on 64 bits
And Extended precision on 80 bits.
37
31/10/2024
40 Representation of real numbers: Floating-point
IEEE 754 Standard : Single precision
MS Exponent Mantissa
1 bit 8 bits 23 bits
MS = 0 if N is positif
Represents the fractional part of the
MS = 1 if N is negative
mantissa.
The exponent is represented with a
bias-127 format.
Exponent = Exponentreel +127
38
31/10/2024
41 Representation of real numbers: Floating-point
IEEE 754 Standard : Single precision
Example 01 : (35,5)10=( ?)IEEE 754 single precision
(35,5)10=(100011,1)2(fixed-point)
=(1,000111x25) (Floating-point)
Eb=E+2p-1-1=5+28-1-1 =5+127=132=(10000100)2
1,M=1,000111M=00011100000000000000000
MS=0 ; It’s a positif number
39
31/10/2024
42 Representation of real numbers: Floating-point
IEEE 754 Standard : Single precision
Example 02 : (+7)10 =(?) IEEE754 single precision
(+7)10=(+111)2=1,11x22
So:
MS=0 (positif sign)
M=11000000000000000000000
E=2Eb=2+127=129=(10000001)2
(+7)10=(01000000111000000000000000000000)IEEE754SP
40
31/10/2024
43 Representation of real numbers: Floating-point
IEEE 754 Standard : Single precision
Example 03 : (-2,25)10=(?) IEEE754 single precision
(-2,25)10=(-10,01)2=-1,001x21
So:
SM=1 (negative sign)
M=00100000000000000000000
E=1Eb=1+127=128=(10000000)2
(-2,25)10=(11000000000100000000000000000000)IEEE754SP
41
31/10/2024
44 Representation of real numbers: Floating-point
IEEE 754 Standard : Double precision
MS Exponent Mantissa
1 bit 11 bits 52 bits
MS = 0 if N is positif
Represents the fractional part of the
MS = 1 if N is negative
mantissa.
The exponent is represented with a
bias-1023 format.
Exponent = Exponentreel +1023
42
31/10/2024
45 Representation of real numbers: Floating-point
IEEE 754 Standard : Double precision
Example 01 : (35,5)10=( ?)IEEE 754 double precision
(35,5)10=(100011,1)2(fixed-point) =(1,000111x25) (Floating-point)
Eb=E+2p-1-1=5+211-1-1 =5+1023=1028=(10000000100)2
1,M=1,000111M=00011100000000000000000000000~0
SM=0 ; it’s positif number
43
31/10/2024
46 Representation of real numbers: Floating-point
La norme IEEE 754 : Exceptions
In addition to normalized floating-point numbers, IEEE 754 also mandates support for certain special
floating-point numbers. Single-Precision Exponent = 8 Fraction = 23 Value
Normalized Number 1 to 254 Anything ± (1.F)2 × 2E – 127
Denormalized Number 0 nonzero ± (0.F)2 × 2–126
Zero 0 0 ±0
Infinity 255 0 ±∞
NaN (not a Number) 255 nonzero NaN
Double-Precision Exponent = 11 Fraction = 52 Value
Normalized Number 1 to 2046 Anything ± (1.F)2 × 2E – 1023
Denormalized Number 0 nonzero ± (0.F)2 × 2–1022
Zero 0 0 ±0
Infinity 2047 0 ±∞
NaN 2047 nonzero NaN
44
31/10/2024
47 Representation of real numbers: Floating-point
La norme IEEE 754 : Exceptions
• Denormalized Numbers
There exists a smallest strictly positive representable number in normalized form. However, the
denormalized representation allows for the representation of even smaller values.
It should be noted that the implicit bit is no longer 1 but 0, and the exponent is set to -126 for single
precision.
For example: Consider a decimal number (N) written in IEEE 754 format (32 bits).
45
31/10/2024
48 Representation of real numbers: Floating-point
La norme IEEE 754 : Exceptions
• Zero
Zero is a special floating-point value with two possible representations: +0 and -0, depending
on the sign bit.
• Infinity
If the exponent bits are set to 255, and the mantissa is 0, then the number represents either
positive infinity (+∞) or negative infinity (-∞) depending on the value of the sign bit..
• NaN
This code is used to represent the result of an exceptional operation and signal calculation errors.
For example et −4
46
31/10/2024
55 Character Representation
Characters include alphabetic letters (A, a, B, B, ...), numbers, and other symbols (>, ;, /, :,
...).
Character representation is achieved through a lookup table that specifies the binary
configuration for each character.
The two most common character encodings are ASCII and UNICODE.
•The encoding in ASCII (American Standard Code for Information Interchange) is based on a
table containing the most commonly used characters in the English language. Each character is
represented using 8 8 bits .
•With 8 bits, you can have 28 = 256 combinations.
47
31/10/2024
56 Character Representation
In this table, the letter A is
located at the intersection of
column 100 and row 0001. The
ASCII code for the letter A is,
therefore, 1000001.
48
31/10/2024
57 Character Representation
L’UNICODE encodes characters using 16 bits, allowing for the encoding of 65 536 (216) different characters.
It was primarily introduced to unify various existing character encodings and to accommodate all existing
alphabets (Latin, Arabic, Chinese, Cyrillic, Bengali, etc.) within a single encoding table.
It is compatible with ASCII, with the first 256 characters in Unicode being the same as those in the basic and
extended ASCII tables
The following table shows Unicode ranges for some alphabets:
49