Date post: | 14-Jan-2016 |
Category: |
Documents |
Upload: | jerry-rodriguez-flores |
View: | 214 times |
Download: | 0 times |
7/18/2019 Week 0 - Lectures
http://slidepdf.com/reader/full/week-0-lectures-5696e09b30e68 1/34
BINARY NUMERATION SYSTEM.1Jean-Pierre Deschamps
University Rovira i Virgili, Tarragona, Spain
7/18/2019 Week 0 - Lectures
http://slidepdf.com/reader/full/week-0-lectures-5696e09b30e68 2/34
0 .11. Computer information representation
A computer receives, stores, processes, transmits data.
, , ,
(video), etc.
Data encoding: strings of zeroes and ones.
Computer technology is based on electronic circuits able to process vectors of 0’s and 1’s (the
so-called digital electronic circuits). For that reason all data are encoded by strings of 0’s and 1’s.
This type of information encoding is called binary encoding system.2
7/18/2019 Week 0 - Lectures
http://slidepdf.com/reader/full/week-0-lectures-5696e09b30e68 3/34
0 .12. Numeration systems
Most used systems:
• Decimal system
• Binary system
• Hexadecimal system
Conversion methods will be presented..
3
7/18/2019 Week 0 - Lectures
http://slidepdf.com/reader/full/week-0-lectures-5696e09b30e68 4/34
0 .12.1 Decimal system
• Uses ten digits:
0 1 2 3 4 5 6 7 8 9
• Positional system : a weight is associated to every digit position so that position is
relevant.
6 5 3Example: 653
653 = 6·102 + 5·101 + 3·100
6 hundreds, 5 tens, 3 units
4
7/18/2019 Week 0 - Lectures
http://slidepdf.com/reader/full/week-0-lectures-5696e09b30e68 5/34
0 .12.2 Binary system
• Uses two digits (binary digits, bits): 0, 1
• Positional system.
Example:
(weights) 23 22 21 20
• To compute the decimal representation, add up the weights corresponding to the
1’s of the binary representation:(1101)2 = 1·2 + 1·2 + 0·2 + 1·2 = 8 + 4 + 0 + 1 = 13
5
7/18/2019 Week 0 - Lectures
http://slidepdf.com/reader/full/week-0-lectures-5696e09b30e68 6/34
0 .1Exercise
Compute the decimal representation of the following binary number: (101001)2
6
7/18/2019 Week 0 - Lectures
http://slidepdf.com/reader/full/week-0-lectures-5696e09b30e68 7/34
0 .1Exercise solut ion
Compute the decimal representation of the following binary number: (101001)2
1 0 1 0 0 1
weights 25 24 23 22 21 20
(101001)2
= 1·25 + 0·24 + 1·23 + 0·22 + 0·21 + 1·20 = 32 + 8 + 1 = 41
7
7/18/2019 Week 0 - Lectures
http://slidepdf.com/reader/full/week-0-lectures-5696e09b30e68 8/34
0 .12.2 Binary system: representation range
• Pure binary system: non-negative number representation.
• With n bits: 2n distinct values.
• Representation range: 0 to 2n - 1.
EXAMPLE: Binary Decimal Binary Decimal
n = 4 bits16 different combinations
from 0 to 15 = 24-1
0000 0 1000 80001 1 1001 9
0010 2 1010 10
0100 4 1100 12
0101 5 1101 13
0111 7 1111 15
8
7/18/2019 Week 0 - Lectures
http://slidepdf.com/reader/full/week-0-lectures-5696e09b30e68 9/34
0 .12.2 Binary system: representation range
If n = 3 : 23 = 8 representable numbers, from 0 to 7.
If n = 4 : 24 = 16 representable , from 0 to 15.
If n = 5 : 25 = 32 representable , from 0 to 31.
6 , …
Example: how many bits do we need to represent 48?
31 ≤ 48 ≤ 63
n=5 n=6
=> to re resent decimal number 48 we need 6 bits: 110000
9
7/18/2019 Week 0 - Lectures
http://slidepdf.com/reader/full/week-0-lectures-5696e09b30e68 10/34
0 .12.3 Hexadecimal system
BINARY HEXA
0 0 0 0 0
0 0 0 1 1
• Uses sixteen dígits:
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F0 0 1 0 2
0 0 1 1 3
0 1 0 0 4• Positional system
(weights) 163 162 161 160
0 1 1 0 6
0 1 1 1 7
1 0 0 0 8
• To compute the decimal representation, add up the digits
multiplied by the corresponding weights:
1 0 0 1 9
1 0 1 0 A
1 0 1 1 B
(3A9F)16 = 3·163 + 10·162 + 9·161 + 15·160 = 1500710 1 1 0 1 D
1 1 1 0 E
1 1 1 1 F
7/18/2019 Week 0 - Lectures
http://slidepdf.com/reader/full/week-0-lectures-5696e09b30e68 11/34
3. Base conversion (HEXADECIMAL to BINARY)
0 .1
5. Cambios de base (BINARY to HEXADECIMAL)
.
hexadecimal 3 A 9
y
• BINARY to HEXADECIMAL: 4 bits → 1 hexadecimal digit (starting from the four
binary 100 1011 1010 0101
r g mos s
hexadecimal 4 B A 511
7/18/2019 Week 0 - Lectures
http://slidepdf.com/reader/full/week-0-lectures-5696e09b30e68 12/34
0 .1Exercise
1101101010011002 = ????16
BINARY HEXA
0 0 0 0 0
0 0 0 1 1
Compute the hexadecimal representation:
0 0 1 0 2
0 0 1 1 3
0 1 0 0 4
0 1 0 1 5
5F2C16 = ?????2
0 1 1 0 60 1 1 1 7
1 0 0 0 8
Compute the binary representation:
1 0 0 1 9
1 0 1 0 A
1 0 1 1 B
1 1 0 0 C
1 1 0 1 D
1 1 1 0 E
1 1 1 1 F12
7/18/2019 Week 0 - Lectures
http://slidepdf.com/reader/full/week-0-lectures-5696e09b30e68 13/34
0 .1Exercise (so lu t ion )
BINARY HEXA
0 0 0 0 0
0 0 0 1 1
Compute the hexadecimal representation:
2 = 160 0 1 0 2
0 0 1 1 3
0 1 0 0 4
0 1 0 1 5
5F2C16 = ?01011111001011002
0 1 1 0 60 1 1 1 7
1 0 0 0 8
Compute the binary representation:
0101 1111 0010 11000101 1111 0010 11000101 1111 0010 11000101 1111 0010 1100
1 0 0 1 9
1 0 1 0 A
1 0 1 1 B
1 1 0 0 C
1 1 0 1 D
1 1 1 0 E
1 1 1 1 F13
7/18/2019 Week 0 - Lectures
http://slidepdf.com/reader/full/week-0-lectures-5696e09b30e68 14/34
0 .14. Base conversion (DECIMAL to BINARY)
5• Divide the decimal number by 2. Divide the obtained quotient by 2. Keep dividing
the obtained uotients b 2 until the obtained uotient is e ual to 1.
• The base 2 number consists of the last quotient 1 and the set of previously obtained
remainders.
Example: 18(10 = ? 10010(2
(10 = · 2 +
18 = 9·2 + 0
9 = 4·2 + 1
4 = 2·2 + 0 = · 18(10 = 10010(2 10010(2
14
7/18/2019 Week 0 - Lectures
http://slidepdf.com/reader/full/week-0-lectures-5696e09b30e68 15/34
Exercise
0 .1
43(10 = binary number?
15
7/18/2019 Week 0 - Lectures
http://slidepdf.com/reader/full/week-0-lectures-5696e09b30e68 16/34
0 .1Exercise solut ion
43(10 = binary number?
43 = 21·2 + 1
21 = 10·2 + 1
= ·
5 = 2 · 2 + 12 = 1 · 2 + 0
43(10 = 101011
16
7/18/2019 Week 0 - Lectures
http://slidepdf.com/reader/full/week-0-lectures-5696e09b30e68 17/34
0 .16. Sum and difference of binar numbers
Sum of 2 bits:
0 + 0 = 0
Difference of 2 bits:
0 - 0 = 0 =
1 + 0 = 1
1 + 1 = 10 (current step bit: 0,
-
1 - 1 = 0
0 - 1 = 11 (current step bit: 1
borrow to the next ste : 1
==
Sum example: Difference example:
1 0 1 0 01 0 1 0 0 1 0 1 =1 0 1 = AA
++ 11 0 10 1 0 1 10 1 1 11 = B= B
-- 11 0 10 1 0 1 10 1 1 1 = B1 = B
1 1 1 1 1 1 0 01 1 1 1 1 1 0 0 0 1 0 0 1 1 1 00 1 0 0 1 1 1 0
1 0 1 1 1 11 0 1 1 1 1 →→ borrowborrow
17
7/18/2019 Week 0 - Lectures
http://slidepdf.com/reader/full/week-0-lectures-5696e09b30e68 18/34
0 .1Exercise
1 01 0 0 1 1 0 1 1 =0 1 1 0 1 1 = AA== 1 01 0 0 1 1 0 0 1 =0 1 1 0 0 1 = AA-- ==
18
7/18/2019 Week 0 - Lectures
http://slidepdf.com/reader/full/week-0-lectures-5696e09b30e68 19/34
0 .1Exercise solut ion
1 01 0 0 1 1 0 1 1 =0 1 1 0 1 1 = AA1 01 0 0 1 1 0 0 1 =0 1 1 0 0 1 = AA
-- ==0 0 1 0 0 1 10 0 1 0 0 1 1
→→ carrycarry
1 1 1 0 1 1 1 01 1 1 0 1 1 1 00 1 0 0 0 1 1 00 1 0 0 0 1 1 0
++ 1 0 11 0 1 00 00 11 11 = B= B
11 0 0 1 11 1 →→ borrowborrow
19
7/18/2019 Week 0 - Lectures
http://slidepdf.com/reader/full/week-0-lectures-5696e09b30e68 20/34
SUMMARY0 .1
Computer information representation.
Numeration systems (decimal, binary, hexadecimal).
Pure binary system and representation range.
Base conversion.
um an erence o nary num ers.
20
7/18/2019 Week 0 - Lectures
http://slidepdf.com/reader/full/week-0-lectures-5696e09b30e68 21/34
PSEUDOCODE.2Jean-Pierre Deschamps
University Rovira i Virgili, Tarragona, Spain
7/18/2019 Week 0 - Lectures
http://slidepdf.com/reader/full/week-0-lectures-5696e09b30e68 22/34
1. Algorithm representation: pseudocode0 .2
Algorithm
Sequence of operations whose objective is the solution of some problem such as:
comp ex compu a on, con o o some p ocess, e c.
The result of the algorithm execution must be independent of the chosen type of
representation.
, ,
diagrams and programming languages.
Similar to programming language but more informal. It uses a mix of
natural language sentences,
,
key words that define basic structures.
22
7/18/2019 Week 0 - Lectures
http://slidepdf.com/reader/full/week-0-lectures-5696e09b30e68 23/34
2. Operations and control structures0 .2
• ASSIGNMENTS
• OPERATORS⁻ Compar son
⁻ Logic operations
⁻ Arithmetic operations
• SELECTION STRUCTURES (DECISIONS)⁻ Simple, Double, Multiple, Case
• ITERATION STRUCTURES (CYCLES)
⁻ While, For
•
23
7/18/2019 Week 0 - Lectures
http://slidepdf.com/reader/full/week-0-lectures-5696e09b30e68 24/34
2. 1 Assignments and types of operators0 .2
ASSIGNMENTS
Assignment instruction <= : allows to store a value within a variable. Examples:
x <= 15, x <= 2x + y + z, etc.
variable <= expression;
w ere x, y an z are var a es.
COMPARISON OPERATORS
Operator Meaning
< Smaller than
> Greater than
= Equal to
≤ Smaller than or e ual to
(1) Sometimes we can use <=
(2) Sometimes we can use >=
=
≥ (2) Greater than or equal to
≠(3) Different from
24
7/18/2019 Week 0 - Lectures
http://slidepdf.com/reader/full/week-0-lectures-5696e09b30e68 25/34
0 .22. 1 Assignments and types of operators
LOGIC OPERATORS
Operator Meaning
og c pro uc
or Logic sum
not Negation
ARITHMETIC OPERATORS
+ Sum
- Difference
* Product
/ Division25
7/18/2019 Week 0 - Lectures
http://slidepdf.com/reader/full/week-0-lectures-5696e09b30e68 26/34
3. Control structures0 .2
SELECTION STRUCTURES
Simple condition yes
If condition then action(s);
end if ;
noaction;
ou e
If condition then action1/s;else action2/s;
conditionno yes
action1;action2;
26
7/18/2019 Week 0 - Lectures
http://slidepdf.com/reader/full/week-0-lectures-5696e09b30e68 27/34
0 .23. Control structures
SELECTION STRUCTURES
Multiple condition1
yes no
If condition1 then action1/s;
elsif condition2 then action2/s;
end if ;
action2;
action1; condition2
Case
end if ;
x
when “value1" => action1;
when “value2" => action2;
“ " =
X
action2;action1; action3; action4;
when “value4" => action4;
end case; 27
7/18/2019 Week 0 - Lectures
http://slidepdf.com/reader/full/week-0-lectures-5696e09b30e68 28/34
0 .23. Control structures (example 1)
y = X/2 , rounded down
Different cases:
• When X is even, the result of the division is exact (whether X is positive or negative)
,
- if X is negative: (X+1)/2- if X is positive (X-1)/2
If (X is even) then y<= X/2;
elsif (X<0) then y <= (X+1)/2;
else y <= (X-1)/2;end if ;
end if ;28
7/18/2019 Week 0 - Lectures
http://slidepdf.com/reader/full/week-0-lectures-5696e09b30e68 29/34
0 .23. Control structures (example 2)
X is a decimal digit: we calculate the binary representation
case x is
“ " = =
when “1" => y <= 0001;……..
“ " = =
end case;
29
7/18/2019 Week 0 - Lectures
http://slidepdf.com/reader/full/week-0-lectures-5696e09b30e68 30/34
0 .23. Control structures
ITERATION STRUCTURES
conditionyes no
While
While condition loop
action/s;
action;
for variable in min to max loo
For
action/s;
end loop;
30
7/18/2019 Week 0 - Lectures
http://slidepdf.com/reader/full/week-0-lectures-5696e09b30e68 31/34
0 .23. Control structures (example 3)
Given two vectors of 8 positions:
, , ……
x(0), x(1), ……x(7)
We want to do the following calculation:
y = a(0) · x(0) + a(1) · x(1) + a(2) · x(2) + ………..+ a(7) · x(7)
for i in 0 to 7 loop
acc <= acc+ a(i) · x(i);
en oop;
31
7/18/2019 Week 0 - Lectures
http://slidepdf.com/reader/full/week-0-lectures-5696e09b30e68 32/34
4. Procedures0 .2
Procedure call name(parameters);
Procedure (subroutine): sequence of instructions (operations and control structures) that
execute some task (algorithm).
A name and a set of parameters are associated to every procedure.
A procedure can be called one or several times within a program. When called, values are given
to its parameters. Algorithm
---------
PROCEDURE
---------call procedure
---------
------------------
---------
call procedure ---------
---------32
7/18/2019 Week 0 - Lectures
http://slidepdf.com/reader/full/week-0-lectures-5696e09b30e68 33/34
4. Procedures (example 1)0 .2
Procedure square_root(x, y, n) is
z = a · √x + b · √y
----
----
end procedure
ALGORITHM
Begin
PROCEDURE
call square_root (x,u,16);
u <= a * u;
call square_root (y,r,16);
*
Algorithm
z <= u + r;
end
square_root
(x,y,n)
---------
---------
end procedure
call square_root (x, u, 16);
u <= a * u;
call square_root (y, r, 16);
r <= b * r;
z <= u + r;33