Chapter 2
Chapter 2
Basic Elements
The computer can process various types of information:
Numerical values, Texts, Images, Sound, …
BUT
Chapter 2: All this information is stored in digital form
Representation of information &
System number
Information
Computer Architecture 1 Course, 1st year Computer Science Engineer 1 Computer Architecture 1 Course, 1st year Computer Science Engineer 2
1
1. Representation of numbers: Representation of numbers in a base b
Number systems
Number systems describe how numbers are represented. • A number (XXX)b indicates the representation of a number
A num ber s ys tem is defined by:
XXX in the base b.
A l p h a b e t ( A ) : A s e t o f s y m b o l s ( n u m b e r s ) : A = { a 1, • The usual bases that we know and use every day are:
a 2, … . , a n } - base 10 (decimal system) to represent different
Rules for wr it ing num bers: J uxtapos ition of quantities, different figures and numbers, and
s ym bols
- base 60 to represent time.
a 1a 3: i s a w o r d
• In a num ber s ys tem, the num ber of distinc t s ym bols is
c alled the bas e of the num ber s ystem (the c ardinal of the How to represent a number in a base b?
s et A) .
If b ≤ 10, we simply use the numbers 0 to b-1
• In c om puting , the m ost us ed bas es are binar y, octal, and
hexadecimal . Example: base 8 (octal system): any number will be the
combination of digits belonging to the set {0,…, 7}
7 8
Computer Architecture 1 Course, 1st year Computer Science Engineer
A number of n digits (symbols) is a sequence (ai), 0 ≤ i ≤ n-1: an- 5368, 135=5*103+3*102 + 6*101 + 8*100 + 1*10-1+3*10-2+5*10-3
1 ….. a1 a0 such that: a0 is the least significant term and an-1 is
the most significant term. Decimal part
Integer part
9 10
Computer Architecture 1 Course, 1st year Computer Science Engineer Computer Architecture 1 Course, 1st year Computer Science Engineer
2
Decimal base to base b (0,23)10=(?)2
• Integer part:
Successive multiplications until having a zero result or obtaining a • Now let's move on to the decimal part :
given precision (0,23)10=(?)2
Example:
0,23x2= 0,46 integer number is 0
(115,23)10= (?)2
0,46x2= 0,92 integer number is 0
With a precision of 6 places after the decimal point. 0,92x2= 1,84 integer number is 1
We treat each part separately 0,84x2= 1,68 integer number is 1
Integral part: 0,68x2= 1,36 integer number is 1
115÷2=57 remainder 1
57÷2= 28 remainder 1
0,36x2= 0,72 integer number is 0
28÷2= 14 remaider 0
14÷2= 7 remainder 0 • Hence: (0,23)10=(0,001110)2
7÷2= 3 remainder 1
3÷2=1 remainder 1 • Final result: (115,23)10= (1110011, 001110)2
1÷2=0 remainder 1 (quotient=0 stop)
Hence: (115)10= (1110011)2 13 14
Computer Architecture 1 Course, 1st year Computer Science Engineer
=b 0 a 0 +b 1 a 1+… b n a n = (∑aibi)10
25 8 25 16 Examples:
1 3 8 9 1 16
• (11011101,1)2 = 2-1*1+ 20*1+21*0+22*1+23*1+24*1+25*0+26*1+27*1= (221,5)10
3 0 1 0 • (175,26)8= 8-1*2+8-2*6 + 80*5+81*7+82*1
• (14)16=160*4+161*1=(20)10
• (1011)2 = (1 × 23 + 0×22 + 1×21 + 1×20)10 = (1×8 + 0×4 + 1×2 + 1×1)10 = (11)10
Conversion from binary base to the Conversion from the octal base to the
octal base binary base
Making 3-bits groups starting from the least significant one. Replace each symbol in the octal base with its 3-bit binary
value
Replace each group with the corresponding octal value. Octale Binaire
Example: ( 213)8
3 binary digits ⇒ one octal digit
2 1 3
( 10111101)2
010 001 101
2 7 5
(275)8
17 18
Computer Architecture 1 Course, 1st year Computer Science Engineer Computer Architecture 1 Course, 1st year Computer Science Engineer
3
Arithmetic operations (the
Application exercises
addition)
In binary In Octal In Hexadecimal Perform the following operations and transform
the result to decimal each time:
The ad d ition
+ 0 1 retain
11
• (1111,101)2+(10,1)2=(?)2
0 0 1 1 111 11
11011
375 1BA • (45)8+(75)8=(?)8
+
1 1 10
+ + • (AB4)16+(253)16=(?)16
33 F6
10110
The multiplication
(110001)2 (430)8 (2B0)16
* 0 1
0 0 0
1 0 1
19 20
Computer Architecture 1 Course, 1st year Computer Science Engineer
• There are at least three techniques allowing the • The other (n-1) bits encode the magnitude (the absolute
representation of signed integers: value) of the number
• W ith n bits, we encode all the numbers between -(2 n-1 -1) and
1. Signed m agnitude representation (2 n-1 -1)
23 24
Computer Architecture 1 Course, 1st year Computer Science Engineer Computer Architecture 1 Course, 1st year Computer Science Engineer
4
Advantages and disadvantages of
One's complement (C1)
signed magnitude
• Advantages: Simple • The first bit is reserved for the sign.
• Disadvantages (limites): • If the number is positive then the number keeps its format.
• If the number is negative then each bit (of the remaining bits) is
Two representations of zero : inverted (0 becomes 1 and 1 becomes 0) (by completing on the left
with 0s to obtain an n-bit code).
On 8 bits : +0 = 00000000
• The number of possible combinations on n bits is 2n
-0 = 10000000 • With n bits, we encode all the numbers between -(2n-1-1) and (2n-1-1)
Multiplication and addition are less obvious • Two combinations for 0
• Examples:
For example, we add -3 and -1 on 4 bits -5 on 8 bits
5= (00000101)2
-5= (11111010)C1
+7 on 8 bits
25 +7= (00000111)2= (00000111)C1 26
Computer Architecture 1 Course, 1st year Computer Science Engineer
5
Representation of real numbers Fixed point
• A real num ber = the integer part + the decim al
• Example: +15,23, -234,01…… part .
• Two questions arise:
• T he integer part is coded o n “p” bits by
1. How to represent the comma in a machine? perform ing successiv e div isions b y 2 .
The designers did not take the comma into account, but
they offered a place in the representation of numbers. • T he decim al part is encoded on “q” bits b y
perform ing successive m ultiplications b y 2 until
2. How to tell the machine the position of the decimal the decim al part is zero o r the num ber of bits q is
point? reached .
0,625*2=1,25
Fixed point Example : 12,625=(?)2 fixed point format 0,25*2=0,5
Floating point Integer part : 12 = (00001100)2 0,5*2=1,0
Decim al part: 0,625 = (?)2
(12,625)10=(001100,101)2
31 32
Computer Architecture 1 Course, 1st year Computer Science Engineer
35 36
Computer Architecture 1 Course, 1st year Computer Science Engineer Computer Architecture 1 Course, 1st year Computer Science Engineer
6
IEEE 754 Coding Steps Application exercise
[Link] of the exponent E (biased/shifted or
normalized) • Question:
Convert the decimal number (12,25)10 in the floating
Exponent (E biased) = dec + 2p-1 – 1 point format according to the IEEE 754 single
precision standard
• Solution:
Single precision (32 bits, p=8) : E = dec +127 Converting the number 12.25 to binary
(12,25)10=(1100,01)2
Double precision (64 bits, p=11) : E= dec +1023 =1,10001*23
Hence
Shift (power)
• 12,25=1,10001*23
37 Th e mantissa (M) 38
Computer Architecture 1 Course, 1st year Computer Science Engineer Computer Architecture 1 Course, 1st year Computer Science Engineer
So, the number (12,25)10 in floating point according to the IEEE 754 S=0 => positive number
single precision standard is : E=(10000010) 2=130 ; E=
dec+ 127 => dec=130-127=3
01000001010001000000000000000000
X= + 1,M * 23 = 1,11010000000000000000000 * 23 (dec=3)
Do NOT mix up conversion of a decimal number to a binary number Character coding is done using a table of
with coding a decimal number with a BINARY CODE. correspondence between characters and binary
1310 = 11012 (This is conversion) num bers.
13 0001|0011 (This is coding)
41 42
Computer Architecture 1 Course, 1st year Computer Science Engineer Computer Architecture 1 Course, 1st year Computer Science Engineer
7
Character encoding: ASCII code The ASCII code table (1)
This code was developed for the English language, so it does not
contain accented characters or language-specific characters.
43 44
Computer Architecture 1 Course, 1st year Computer Science Engineer Computer Architecture 1 Course, 1st year Computer Science Engineer
45 46