You are on page 1of 35

Arithmetic fundamentals.

Numbering systems.
Converting numbers from one
number system to another
Position and non-position numbering systems.
Fundamentals of numbering systems. Decimal, binary,
hexadecimal and octal numbering system. Rules for
conversion of numbers from decimal to binary system.
Reverse conversion. Conversion of numbers in
hexadecimal system

The state of modern computing


Understanding the design process, the organization of
the computers, the technological factors and the
performance evaluation are at the core of the state of
art of modern computers
Technology

Parallelism

Applications
Computer architectures:
Instruction set architecture
Machine organization
Hardware

Operating
systems

Performance
measurement
and evaluation

Programming
languages
Interface design

History

Computer functioning
A typical application program, widely used (like word
processor, email, spreadsheet, etc) consist of tens,
hundreds of thousands or even more lines of code
(MSOffice 2013 44 M lines of code) 1M = 18 000
pages printed text
During its functioning the program also relies on other
software like system software, including operating
system (Windows 7 40 M lines code), compilers and
assemblers
System software software providing commonly used
services to application programs
Operating systems a program that manages and
supervises the computer resources (units) during the
functioning of the computer

Computer functioning
Some of the most important functions of
the operating system are
- handling basic I/O operations
- allocating storage and memory
- sharing the resources (processor,
memory) of the computer among multiple
applications
Application software
System software
Hardware

Computer functioning
Every computer must perform arithmetic
operations
For example in assembler (a low level
programming language, unlike C, Java, C++
which are high level programming language) the
instruction:
add a, b, c
makes the computer to add 2 variables - b and
and place the result in the variable
The same action in would be: = b +

Computer functioning
The translation of a high level language program
like C, where many actions are similar to those
in mathematics, into an assembly language
program is done by a program called compiler
The reason for this is that the high level
language programs are designed to be
convenient for use of the programmers who
write down algorithms and present tasks in those
languages, while the low level languages are
designed to be close and matching as much as
possible the hardware of the computer
/processor

Computer functioning
Low level languages (assemblers) are
being also translated into machine
language (or machine code), which can be
executed by the processor of the
machine
The machine code is loaded into the
memory of the system (computer) and the
processor is told to start executing this
code

Computer functioning
Unlike in the high level languages, the operands
for the arithmetic instruction in the example
above, which can be handled by the processor
are limited by the number of registers that exist
in the particular processor
A register is (in general) a place, where
variables are kept and can be accessed by the
programmers when the computer is ready for
work

Computer functioning
In addition to arithmetic, the
computers/processors also execute other type of
instructions:
Logical (logic operations AND, OR)
Control (jump, branch)
System (system calls for error, virtual
memory)
Data transfer (moving data between registers,
memory)
Floating point
On strings (comparison, concatenation)
Graphical, etc.

Computer functioning
Modern computers function on two main principles:
- the instructions are represented as numbers (eg. in
MIPS architecture, the instruction add Rd=Rs+Rt is
presented as: 20 (rs) (rt) (rd) (shamt) (funct) )
- programs are stored in digital form in the memory of
the computer and can be written and read, just like
numbers
These principles are the fundamentals of the memory
stored program the memory stores the program for
the compiler, the corresponding assembly language
program, the text used by the compiler and the
generated machine code

C program
Compiler
Assembly language program
Assembler

A translation hierarchy for C. A high-level-language program is compiled


into an assembly language program and then assembled into an object
module in machine language. The linker combines multiple modules with
library routines to resolve all references. The loader then places the
machine code into the proper memory locations for execution by the
processor. To speed up the translation process, some steps are skipped or
combined together. Some compilers produce object modules directly, and
some systems use linking loaders that perform the last two steps. To
identify of file, UNIX follows a suffix convention for files: C source files
are named X.C, assembly files are X.S, object files are named X.O,
statically linked library routines are X.A, dynamically linked library
routes are X.SO, and executable files by default are called a.out. MSDOS uses the suffixes .C, .ASM, .OBJ, .LIB, .DLL, and .EXE to the
same effect.

Object: Machine language module

Object: Library routine (machine language)

Linker
Executable: Machine language program
Loader
Memory

High level language program (C)

swap(int v[], int k)


{ int temp;

temp = v[k];
v[k] = v[k+1];
v[k+1] = temp
}

compiler

Assembly language program (MIPS)

swap:
muli $2, $5, 4
add $2, $4, $2
lw $15, 0($2)
lw $16, 4($2)
sw $16, 0($2)
sw $15, 4($2)
jr $31

assembler

Binary machine language program (MIPS)

00000000101000010000000000011000
00000000000110000001100000100001
10001100011000100000000000000000
10001100111100100000000000000100
10101100111100100000000000000000
10101100011000100000000000000100
00000011111000000000000000001000

Computer functioning the stored


program concept
The stored program allows
the computer, who runs an
accounting program to turn
into a computer that runs a
program for writing books.
The change occurs with
loading the necessary
programs and data in the
memory, after which the
computer starts the required
program from a pre-defined
memory location. The
instructions and data are
treated in the same way,
which simplifies both the
hardware and software.
Memory technology used for
data is also used for
compilers (translating code

Memory
Accounting program
(machine code)
editor (machine code)

Processor

C compiler
(machine code)
Data salaries
Text book
C program code

Numeral systems positional and


non-positional
For a non-positional system, the value of the
digit is not dependent on its place in the number.
Such systems are the Roman, Greek, etc..
The Roman numeral system uses the digits
(1000), D (500), C (100), L (50), X (10), V (5), I
(1). When this symbols are given in a decreasing
order value, they are added (eg. VI = 5+1), when
a smaller digit stands before a greater one
their values are substracted eg. IV = 5 - 1

Non-positional numeral systems


Greek numeral system, Each unit (1, 2, , 9) was
assigned a separate letter, each tens (10, 20, , 90) a
separate letter, and each hundreds (100, 200, , 900) a
separate letter. This requires 27 letters, so the 24-letter
Greek alphabet was extended by using three obsolete
letters. To distinguish numerals from letters, former were
followed by the symbol . Example: 241 is represented
as (200 + 40 + 1).
The Attic numerals were used by the ancient Greeks
and resembles the Roman numeral system (the
correspondence with the Roman system is I = I, V =
(), X = (), L = , C = H, D = , M = ). Unlike
it, the Attic system contains only additive forms i.e. 4 is
written as , not as .

Positional numeral systems


With a positional numeral system, the value of each
digit is given by the its position in the number.
The number of different digits used in a positional
numeral system is called the base of the system (P).
The digits are basic symbols from 0 to - 1 (the base 1). For example in decimal system = 10 and the digits
used are from 0 to 9. In the positional numeral systems,
the value of each position is on as many orders bigger
than its neighbor on the right, as is the base of the
system (in decimal system 10 times). For this reason,
to represent the next number after the bigger digit, a 1
must be placed and moved to the left for example 9 + 1
is presented as 10.

Positional numeral systems


Digit 0 shows that there are no meaning digits in the
corresponding position. No positional number system is
possible without such digit. Hindus are the first to use 0
for empty positions. At present, the most commonly used
system of numerals is the Arabic numerals.
Two Indian mathematicians are credited with developing
them. Aryabhata of Kusumapura developed the placevalue notation in the 5th century and a century later
Brahmagupta introduced the symbol for zero. The
numeral system and the zero concept, spread to other
surrounding countries so the Arabs adopted it and
modified them.

Positional numeral systems


In this system, the sequence 20 822 denotes the number
2.104 + 0.103 + 8.102 + 2.101 + 2.100. Having in mind that
each position on the right is 1/10 th of the value, and
using a dot to divide the digits into two groups, one can
also write fractions in the positional system. For
example, the base-2 numeral 10.11 denotes 121 +
020 + 121+ 122 = 2.75.
The Chinese Counting rods are small bars, typically 3
14 cm long, used by mathematicians for calculation in
ancient China, Japan, Korea and Vietnam. They are
placed either horizontally or vertically to represent any
number and any fraction. Written forms based on them
are called rod numerals. They are a true positional
numeral system with digits for 1-9 and a blank for 0, from
the Warring states period (475 BC) to the 16th century.

Numeral systems
In general, if p is the base, one writes a number in
the numeral system of base p as:
N = an p n + an 1 p n 1 + ... + a1 p1 + a1 p p 1 + ... + a( k 1) p ( k 1) + a k p k

The digits are natural numbers between 0 and p1,


incl.
0 ai p 1

The number is presented by the form:

a n a n 1 ... a1 a 0 a 1 ... a k

The decimal numeral system


The decimal numeral system (also called base
ten or occasionally denary, dec for short)
has ten as its base. It is the numerical base most
widely used by modern civilizations
The base 10 is the number of fingers of people
the first tools for computing
The digits used are from 0 to 9, there is no digit
for 10!!!
The system is used in computing for financial
operations one can not use other systems (or
floating point presentation of big numbers), as
they are not accurate for such use
Abbreviated as (dec)

Binary numeral system


The first known description of a binary numeral system
was given by the Indian scholar Pingala (around 5th2nd
centuries BC), binary combinations were found in China,
Africa, and other places
The simplest numeral system (also called base-2
number system), represents numeric values using only
two symbols: 0 and 1.
Digits: 0,1
0 = 0, 1 = 1, 2(dec) = 10, 3(dec) = 11, 4(dec) = ?
101112 = 2310
2410= ? 2
Even though it is very simple, the binary system has a
significant shortcoming the numbers have too many
digits!

Octal numeral system


The octal numeral system, or oct for
short, is the base-8 number system, and
uses the digits 0 to 7
Number 0 = 0, 1 = 1, 2 = 2, 3 = 3, 4 = 4, 5
= 5, 6 = 6, 7 = 7, 8(dec) = 10(oct), 9(dec) =
11(oct), 10(dec) = 12(oct)...
2310=278
2410= ? 8
3210= ? 8

Hexadecimal numeral system


The hexadecimal numeral system, or hex for
short, is the base-16 number system, and uses
the digits 0 to 9, , b, c, d, e, f (or A, B, C, D, E,
F)
Number 0 = 0, 1 = 1, 2 = 2, 3 = 3, 4 = 4, 5 = 5, 6
= 6, 7 = 7, 8 = 9, 9 = 9, 10(dec) = A(hex),
11(dec) = B (hex), 12(dec) = C(hex), 13(dec) =
D(hex), 14(dec) = E(hex), 15(dec) = F(hex),
16(dec) =...
2310=1716
2410= ? 16
3210= ? 16

Why dont computers use decimal


numeral system ?
- ENIAC (the first electronic computer) uses 10 vacuum
tubes / digit
Its implementation with electronic elements is
difficult:
1) For storage
2) To transmit - high precision is needed to code 10
levels of signal on a single wire
3) o apply digital logical functions

- addition, multiplication, etc.


Digital electronics operate with only two voltage levels of
interest: a high voltage and a low voltage. All other
voltage values are temporary and occur while
transitioning between the values

Digital presentation
Presentation in binary system
number 1521310 is 111011011011012
number 1.2010 is 1.0011001100110011[0011]2
number 1.5213 X 104 is 1.110110111011012 X 213

Electronic presentation
Easy to implement elements with two stable states
Reliable transmission on lines with noise or low reliability
0

3.3V
2.8V
0.5V
0.0V

Easy to implement arithmetic functions

task
What are the digits that are used by a
base p number system ( 2 positive
integer), :
) 0, 1, 2, 3, , - 1, ;
b) 0, 1, 2, 3, , - 1;
c) 0, 1, 2, 3, , - 1, , + 1;
d) 1, 2, 3, 4, , 1;
e) none of the above.

task
If 2 is a positive integer every positive number can be
represented of the form:
N = anpn + an-1pn-1 + + a1p1 + a0p0,
where ai is an integer and :
) 0 ai p-1; i = 0, , n; an 0,
and this is the only representation;
b) 0 ai p; i = 0, , n; an 0,
and this is the only representation;
c) 0 ai p-1; i = 0, , n; an 0,
and this is not the only representation.

An algorithm for conversion of numbers from decimal to


binary system
Start

The number is divided by and


get quotient and reminder. The
reminder is being recorded.

no

quotient = 0

Take the quotient as a


number.

yes

All
reminders
are
recorded in reverse
order. The result is the
number in base system

End

Example: Convert the decimal number 53 into base 2 system and base 8
system.
Applying the algorithm above:

53 : 2 = 26 and reminder 1
25 : 2 = 13 and reminder 0
13 : 2 = 6 and reminder 1
6 : 2 = 3 and reminder 0
3 : 2 = 1 and reminder 1
1 : 2 = 0 and reminder 1

53 : 8 = 6 and reminder 5
6 : 8 = 0 and reminder 6
53 = 65(8)*
Check:
65 (8) = 6 . 81 + 5 . 80 = 48 + 5 = 53(10)

Check:
53 = 110101(2) = 1 . 25 + 1 . 24 + 0 . 23 + 1 . 22 + 0 . 21 + 1 . 20 =
= 32 + 16 + 4 + 1 = 53
The reverse conversion from -base into decimal system is done by
multiplying the digits at each position to the power of , corresponding to the
position in the number (see the examples for the check for correctness
above).

Task
Convert the decimal number 127 into base
2 system
Check by the reverse conversion (from
base to into decimal)

Reverse conversion
binary -> decimal
I approach
Example : Let the number 101011 is in binary system. To convert it
in decimal, we must sum the weights of those positions, that have
logical 1. Each digit of the binary number is multiplied by the power
of 2, that corresponds to its position of the place of the 1. The one at
the most right position has the power of 0.
101011 = 1 * 25 + 0 * 24 + 1 * 23 + 0 * 22 + 1 * 21 + 1 * 20 = 43
II approach
Example : Let the number 101011 is in binary system. To convert it
in decimal, we must sum several numbers. Each number is 2 on the
power of n, n being the consecutive number of the digit 1 in the
binary number, the one at the most right position is 0.
101011 = 20 + 21 + 23 + 25 = 1 + 2 + 8 + 32 = 43

Binary-to-octal and Back


Each binary number can be converted into octal by
splitting the binary number at triads. After that, each
triad is substituted by the corresponding octal
number/digit according to the table bellow.
Octal digit

Binary number

Octal digit

Binary number

0
1
2
3

000
001
010
011

4
5
6
7

100
101
110
111

Binary-to-Hexadecimal and Back

Convert the following hexadecimal and binary numbers into the other base:
eca86420(hex)
0001

0011

0101

1001

1101

1111(two)

eca86420(hex)

1110

1100

1010

1000

0110

0100

0010

0000(two)

0111

1001

1011

1101

1111(two)

And then the other direction too:


0001

0011

0101

1011

Just a table lookup one way:

0111

13579bdf(hex)

Convert

12610= ? 16
12610= ? 8
12610= ? 2
3016= ? 10
308= ? 10
10000000010= ? 2

Tasks (now)
What do you use the high level programming languages
for?
Under which control is the coordination and
synchronization of the various components of the
computer?
Name at least 3 basic hardware computer components
and 2 important software products give 1-2 examples..
Describe the work (main functions, principles) of the
linker (link editor) - 1 page (home)
Write down how many lines of code are 3 of the
programs which you are using (home)

You might also like