0% found this document useful (0 votes)
3 views8 pages

Chapter 2

The document discusses the representation of various types of information in computers, including numerical values, text, images, and sound, all stored in digital form as binary sequences. It outlines the coding process of information, which involves digitalization, binary encoding, and physical representation, as well as the different number systems used in computing such as binary, octal, and hexadecimal. Additionally, it covers arithmetic operations in these systems and the encoding of natural and signed integers.

Uploaded by

zsam20710
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)
3 views8 pages

Chapter 2

The document discusses the representation of various types of information in computers, including numerical values, text, images, and sound, all stored in digital form as binary sequences. It outlines the coding process of information, which involves digitalization, binary encoding, and physical representation, as well as the different number systems used in computing such as binary, octal, and hexadecimal. Additionally, it covers arithmetic operations in these systems and the encoding of natural and signed integers.

Uploaded by

zsam20710
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

Part I: Representation of the information

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

2023-2024 Instructions Data

Computer Architecture 1 Course, 1st year Computer Science Engineer 1 Computer Architecture 1 Course, 1st year Computer Science Engineer 2

Coding of information Some sizes


Whatever its nature (number, text, image, sound, 210 bits = 1024 bits = 1 Kb (1 Kilo bits) / 210 Ø = 1024 Ø =
1 KØ (1 Kilo Ø)
or video), digital information processed by a
210 Kb = 1024 Kb = 1 Mb (1 Mega bits) / 210 KØ = 1024
computer is always represented in binary form (a
KØ = 1 MØ (1 Mega Ø)
sequence of 0 and 1). For example: 01111011,
210 Mb = 1024 Mb = 1 Gb (1 Giga bits) / 210 MØ = 1024
11000000….. MØ = 1 GØ (1 Giga Ø)
 The smallest unit of information transmitted by a
210 Gb = 1024 Gb = 1 Tb (1 Tera bits)/ 210 GØ = 1024 GØ
computer is called Bit (BInary digiT) (which can take
= 1 TØ (1 Tera Ø)
two values: 0 or 1)
 A unit of information made up of 8 bits is called a
“byte”
Computer Architecture 1 Course, 1st year Computer Science Engineer 3 Computer Architecture 1 Course, 1st year Computer Science Engineer 4

Definition of Information Coding Steps in coding information


The coding of information consists of establishing a The coding of information passes by three steps:
correspondence between the (usual) external
representation of the information (text, number, image,
etc.), and its internal representation in the machine, which 1. Representation of information by a series of numbers
(Digitalization)
is always a series of bits.
2. Encoding each number in binary form
Example: the number 22
3. Represent each binary element by a physical state
(electrical signal)
• Its external representation = 22
• Its internal representation (in binary) = 00010110
How to represent numbers (integers, real, etc.) and
characters (letters, mathematical symbols, etc.) in the
machine?
6
Computer Architecture 1 Course, 1st year Computer Science Engineer 5 Computer Architecture 1 Course, 1st year Computer Science Engineer

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

Representation of numbers in a base b Decimal system


(continued) • It is the number system that we frequently use in our daily activities.
• Based on 10 symbols {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} === base 10
If b > 10, we simply use the numbers 0 to 9 then the letters in • It is a positional system: Each position has a weight.
alphabetical order.
Example:
The number 5368 is written as following :
Example:
5368 = 8*100 +6*101 +3*102 +5*103
Base 16 (hexadecimal system): any number will be the
combination of symbols belonging to {0,…, 9, A, B, C, D, E, F}
Low weight Heavy weight
such that: (A=10 , ….., F=15).

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

Binary system Transcoding: Bases change


Tr ans c oding ( or bas es c onv er s ion) is the oper ation, whic h
• Base (b)=2 allows to g o fr om the r epr es entation of a num ber in one bas e
to its r epr es entation in another bas e.
• The system used in computers
• It uses two digits {0,1} Decimal Base b
Number N= integer part, decimal part (example: 15, 23)
• Example: (10111101)2

• The polynomi al form : Integ er p art: T he successive division method


Divide the number by B N B
(10111101)2 =20*1+21*0+22*1+23*1+24*1+25*1+26*0+27*1 T hen t he quot i ent by B
R1 q1 B
= (190)10
and so on until obtaining a zero quotient
R 2 q2 B
take the remainders of successive divisions on R 3 qn B
the base X in the opposite direction.
Rn 0
11 (N) 1 0 = (R n . . R 3 R 2 R 1 ) B 12
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

Decimal Base to the Octal and Conversion from base b to the


Hexadecimal base decimal base
• Use polynomial expansion
Decimal  Octal Decimal  hexadecimal
X = (an.. a2a1a 0) b

=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

• (16257)8 = 1 × 84 + 6×83 + 2×82 + 5×81 + 7×80 = 1×4096 + 6×512 + 2×64 + 5×8 + 7

(25)10= (31)8 (25)10= (19)16 = 4096 + 3072 + 128+ 40 + 7 = 7343


 (F53)16 = 15 × 162 + 5 × 161 + 3 × 160 = 15 × 256 + 5 × 16 + 3 = 3840 + 80 + 3 = 3923
15 16
Computer Architecture 1 Course, 1st year Computer Science Engineer Computer Architecture 1 Course, 1st year Computer Science Engineer

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

Coding of natural (unsigned) integers


2. Internal data representation -pure binary code-
 A na t ur a l num b e r is a p o s it iv e o r z e r o int e g e r.
 To e nc o d e na t ur a l num b e r s , we us e p ur e b in a r y c o d e .
Unsigned Integers  T he na t ur a l num b e r is r e p r e s e nt e d in b a s e 2 o n n b it s .
 T he r a ng e o f num b e r s o n n b it s is : [ 0 , 2 n - 1 ]
 W it h n b it s , we c a n r e p r e s e nt 2 n num b e r s .

A number N Signed Integers


Example:
• On a byte, (17) 10 is coded in pure binary: 00010001
Real (fixed point, floating-
point)  The number of bits to use depends on the range of
numbers we want to use
 Using 1 byte (8 bits): we can code 2 8 values: [0 ; 255]
 Using 2 bytes (16 bits): we can encode 2 16 values: [0 ; 2 16-1 ]
 Using (n bits): we can code 2 n values: [0 ; 2 n-1 ]
21 22
Computer Architecture 1 Course, 1st year Computer Science Engineer

Coding of signed integers Signed magnitude representation


• These are num bers with a + or - sign. The most significant bit is used to represent the sign of the number
• 1: for a negative number
Example: -24, +354,….. • 0: for a positive number

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

2. One's com plement representation (C1). • Example :


• On 8 bits, we can encode the numbers -13 and +17 in signed
3. Two’s com plement representation (C2) magnitude as follows:
-13 is coded by: 1 0 0 0 1 1 0 1
+17 is coded by: 0 0 0 1 0 0 0 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

Addition and subtraction in C1 Two's complement (C2)


It is based on the following principle: The represent ation of a number X in t wo's com plem ent on n bit s i s
• If no carry is generated by the sign bit then the result is correct and it is done as f ol l ows:
represented in C1.
• i f ( X > = 0 ) ( n u m b e r f r o m 0 t o ( 2 n-1 - 1 ) ) t h e n X i s c o d e d i n t h e s a m e
• Otherwise, it will be removed and added to the result of the operation, this w a y a s i n p u r e b i n a r y,
is represented in C1.
• i f ( X < 0 ) ( n u m b e r f r o m - ( 2 n-1- 1 ) t o 0 ) t h e n :
 Example 1:
 C od e | X| i n bi na ry by c om pl et i ng o n t h e l ef t wi t h 0 t o o bt ai n an n-
-14+5 on 5 bits
bit code
-14+5=(-1110+0101)2=(11110)SM+(00101)SM= (10001)C1+(00101)C1
 Inv ert all bits of the binary representation (one's complement) ;
=(10110)C1 no retain, so the result is correct and it is written in C1.
 Add 1 t o t he resul t (t wo' s com pl em ent or C2)
We must transform it into a binary number then decimal:
 The num ber of possi bl e com bi nati on s on n bi ts i s 2n
(10110)C1=(11001)SM= (-1001)2=-9
 W i t h n b i t s , w e e n c o d e a l l t h e n u m b e r s b e t w e e n -(2n-1) and (2n-1-1)
 Exemple 2:
14-6 on 5 bits Examples:
-5 on 8 bits
14-6=(1110-0110)2=(01110+10110)SVA=(01110+11001)C1=(00111)C1
-5= (00000101)2 = (11111010)C1 = (11111011)C2
with retained 1, the latter is added to the result obtained and we obtain
 +7 on 8 bits
(01000)C1= 8 since the number is positive
27 +7= (00000111)2= (00000111)C1 = (00000111)C2 28

Representation of some numbers on 4 bits


C2 MS Decimal
Addition and subtraction in C2
0000 0000 0 It is based on the following principle:
0001 0001 +1 • If there is a carry generated by the sign bit, it is ignored and the result is in C2
0010 0010 +2 • Otherwise the result is correct and in C2
0011 0011 +3 Example 1:
0100 0100 +4 -14+5 on 5 bits
0101 0101 +5 -14+5=(-1110+0101)2=(11110)SM+(00101)SM= (10001)C1+(00101)C1
0110 0110 +6 = (10010)C2+(00101)C2 =(10111)C2 no carry, so the result is correct and it is
0111 0111 +7 written in C2
1000 -8 We must transform it into a binary number then decimal
1001 1111 -7 (10111)C2= (10110)C1 =(11001)SM= (-1001)2=-9
1010 1110 -6 Example 2:
1011 1101 -5 14-6 on 5 bits
1100 1100 -4 14-6=(1110-0110)2=(01110+10110)SAV=(01110+11001)C1=(01110+11010)C2=(01000)C2
1101 1011 -3 with a carry 1, the latter is ignored and we obtain
1110 1010 -2 (01000)C2= (00110)C1=(00110)SAV=8 since the number is positive
1111 1001 -1
29 30
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

The IEEE 754 standard


Floating point (IEEE 754 standard)
(single precision)
• In c om puti ng, the IE EE 754 s tandard has bec om e
es tabl i s hed for the c odi ng of fl oati ng num bers .
• In the IE E E 754 s tandard, a floati ng poi nt num ber i s • Single precision on 32 bits
al ways repres ented by a tri pl e
 1 bit of the sign
(S; E ;M)
 S: the sign is coded on 1 most significant bit  8 bits for the exponent
(1: negative and 0 positive)  23 bits for the mantissa
 E: the exponent
 M: the mantissa The sign The exponent The Mantissa

The sign The exponent The Mantissa 1 bit 8 bits 23 bits

1 bit P bits q bits


33 34
Computer Architecture 1 Course, 1st year Computer Science Engineer Computer Architecture 1 Course, 1st year Computer Science Engineer

IEEE 754 standard (double


T h e IE E E 754 sta n d ard
precision)
IEEE 754 Coding Steps:
• Double precision on 64 bits :
[Link] representation of the number X in
floating point format : X= ± 1,M . 2dec
1 bit of the sign
11 bits for the exponent • Example:
 52 bits for the mantissa
(24,5)10=(11000,1)2 (fixe point)
The sign The exponent The Mantissa
= + 1,10001 * 2 4 (floating point)
1 bit 11 bits 52 bits

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

Application exercise Converting IEEE 754 to Decimal


(continued)
• Estimation of the elements of the number Conv erting a num ber X from IEEE 754 to decim al
m eans decom posing this num ber into its elem ents :
T he s ig n (S) =0 (pos itiv e num ber)
S,E ; then estim ating its representation in floating
The 8-bit exponent : E=dec+127=3+127=130=> (10000010)2 point form at (X= ± 1,M . 2dec )
 T he mantissa M on 23 bits => 10001000000000000000000 Example:
• X=(010000010110100000000000000000000)
0 10000010 10001000000000000000000 • X= 0 10000010 110100000000000000000000
M
S E
1 bit
8 bits 23 bits

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)

39 X=+ (1110,10) 2 = (14,5)10 40


or more readably in hexadecimal representation (41040000)16 Computer Architecture 1 Course, 1st year Computer Science Engineer

Binary Coded Decimal (BCD) 3. Characters encoding


 T he BCD code is the 8,4,2,1 code .
 8 , 4, 2, and 1 are w eights
 The characters:
Alphabetical (A-Z , a-z),
 This code is the sim plest, m ost intuitive binary
code for decim al digits a n d uses the sam e pow ers o f Digital (0,1,2,3,4,5,6,7,8,9),
2 a s a binary num ber, b u t onl y encodes the first ten Punctuation( ;. ? ! … . )
v alues from 0 to 9 .
Specials (&, $, %,,…)
Exam ple : 12 (1100 in pure binary, 0001 0010 in DCB)

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)

 ASCII (American Standard Code for Information Interchange)


is a computer standard for character encoding that emerged
in the 1960s.
 The basic ASCII code represented 7-bit characters (128
possible characters, from 0 to 127).
o Codes from 48 to 57: numbers in order (0,1,…,9)
o Codes from 65 to 90: capital letters (A….Z)
o Codes from 97 to 122: lowercase letters (a….z).

 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

Extended ASCII code The ASCII code table (2)


 The ASCII code has been extended to 8 bits to be able to
encode more characters (0 to 255) => extended ASCII code.
 Allows us to code accented characters: à, é, è,…etc.

45 46

Examples of ASCII encoding Unicode code


 Developed in 1991
Binary Hexadecimal Decimal  It uses 16 bits to represent 65,536 characters (0 to
H = 01001000 = 48 = 72
e = 01100101 = 65 = 101 65,535)
l = 01101100 = 6C = 108  Unicode defines tens of thousands of codes, but the
l = 01101100 = 6C = 108
o = 01101111 = 6F = 111 first 128 remain compatible with ASCII.
, = 00101100 = 2C = 44  It codes most alphabets: Arabic, Chinese, Turkish, etc.
Espace = 00100000 = 20 = 32
w = 01110111 = 77 = 119  We refer to a character by its number written in
o = 01100111 = 67 = 103
r = 01110010 = 72 = 114
hexadecimal preceded by “U+”.
l = 01101100 = 6C = 108  For example, the Latin letter “a” corresponds to
d = 01100100 = 64 = 100
U+0061 (in hexadecimal)
 [Link]
47 48
Computer Architecture 1 Course, 1st year Computer Science Engineer Computer Architecture 1 Course, 1st year Computer Science Engineer

You might also like