Submitted by: Miguel Mendoza
Chapter 2
Computer Number Systems and Operations
A (VERY) SHORT INTRODUCTION TO COMPUTERS TO
COMPUTERS
Chapter 2. Computer Number
Systems and Operations
MOTIVATION
What is a computer?
What does it do?
How does a computer do what you ask it to do?
Chapter 2. Computer Number
Systems and Operations
Computers…defined
A computer is any programmable machine which executes and responds
to a given set of instructions. It is a device which is capable of these three
core processes:
- Receive data
- Process, manipulate, store and retrieve that data
- Provide useful output
Something to think about: In this age of smartphones and tablets, can
you consider them as computers?
Chapter 2. Computer Number
Systems and Operations
Computers are dumb!
Computers are dependent on instructions:
- They ultimately depend on pre-specified instructions given by the users
No IQ!
- A computer does only what it is instructed to do. Nothing Else. (What about
Artificial Intelligence?)
No feelings!
- Devoid of emotions. Pseudo-emotions (such as in Tamagotchi) are still
PROGRAMMED by humans.
KEYWORD: Programming
Chapter 2. Computer Number
Systems and Operations
NUMBER SYSTEMS
Chapter 2. Computer Number
Systems and Operations
Decimal Number System
Also called Hindu-Arabic, or Arabic, number system.
It is a positional numeral system employing 10 as the base and requiring
10 different numerals. In this scheme, the numerals used in denoting a
number take different place values depending upon position.
0123456789
Example: 381.61 can be written in base 10 as 3x102 + 8x10 + 1x100 +
6x10-1 + 1x10-2
Exercise: Write 54,326.87 in base-10 system
Chapter 2. Computer Number
Systems and Operations
Binary Number System
The binary number system is a positional number system which uses a
base of 2.
This system uses only two binary digits or bits (Binary digITS)
The modern binary system is proposed by Gottfried Leibniz.
Chapter 2. Computer Number
Systems and Operations
Conversion 1: Decimal to Binary
1. Divide the number by two
2. Separate the whole number quotient and its remainder (which is either
0 or 1
3. Divide the resulting quotient by 2
4. Separate again the new quotient and its remainder
5. Repeat Steps 3 and 4 until the quotient becomes 0
6. The series of remainders, from the newest to the first remainder is the
binary form of the number
Chapter 2. Computer Number
Systems and Operations
Conversion 1: Decimal to Binary
Example 1: Convert 239 into a binary number
Divisions Quotient Remainders
239/2 119 1
119/2 59 1
59/2 29 1
29/2 14 1
14/2 7 0
7/2 3 1
3/2 1 1
½ 0 1
Chapter 2. Computer Number
Systems and Operations
Conversion 1: Decimal to Binary
Exercise: Convert the number 1052 into a binary number
Chapter 2. Computer Number
Systems and Operations
Conversion 2: Binary to Decimal
1. Count the number of bits in the binary number, denoted by n and get n-
1
2. Starting from the left, multiply the first bit by 2n-1 , the second bit by 2n-2
until the last bit by 20
3. Add all the products; the sum is the decimal converted form of the
binary number system.
Chapter 2. Computer Number
Systems and Operations
Conversion 2: Binary to Decimal
Example 1. Convert 11101111 into a decimal number
The binary number has 8 bits, hence n-1=7
11101111 = 1x27 + 1x26 + 1x25 + 0x24 + 1x23 + 1x22 + 1x21 + 1x20
= 128+64+32+0+8+4+2+1
=239
Exercise: Convert 10010001101 into a decimal number
Chapter 2. Computer Number
Systems and Operations
Note!
To avoid confusion, when writing 2 different number systems, we usually
write the base of the number system.
23910 =111011112
Chapter 2. Computer Number
Systems and Operations
Octal Number System
The octal number system is just a number system whose base is 8. The
digits used in this system are the digits from 0 to 7.
Chapter 2. Computer Number
Systems and Operations
Conversion 3: Decimal to Octal
Follow the steps used in the decimal-binary conversion, this time dividing
by 8.
Example: Convert 3452 into its octal form
Division Quotients Remainders
3452/8 431 4
431/8 53 7
53/8 6 5
6/8 0 6
Therefore, 345210 = 65748
Chapter 2. Computer Number
Systems and Operations
Conversion 4: Binary to Octal, vice versa
In converting octal numbers into binary numbers, the octal-decimal-binary
route is not necessary. Just take note of the following table
Binary Octal
000 0
001 1
010 2
011 3
100 4
101 5
110 6
111 7
Chapter 2. Computer Number
Systems and Operations
Conversion 4: Binary to Octal, vice versa
Every octal digit has a corresponding 3 bit binary form
Example: Convert 654102 into its binary form
6541018= 110 101 100 001 000 0102
Exercise: Convert 736102 into its binary form
In reverse, the binary-octal conversion is done by grouping the binary
number into groups of three, starting from the right and convert each
group into its octal form.
Exercise: Convert 1001010 to octal form
Chapter 2. Computer Number
Systems and Operations
Hexadecimal Number System
The hexadecimal number system uses the number 16 as its base.
Therefore, its form must have 16 different hexadecimal digits.
Chapter 2. Computer Number
Systems and Operations
Conversion 5: Decimal to Hexadecimal, vice
versa
Similar to the other conversion, but this time change the base to 16.
Example: Convert 45887374 into its hexadecimal form
Divisions Quotients Remainders Hexadecimal
45887374/16 2867960 14 E
2867960/16 179247 8 8
179247 /16 11202 15 F
11202/16 700 2 2
700/16 43 12 C
43/16 2 11 B
2/16 0 2 2
Chapter 2. Computer Number
Systems and Operations
Conversion 5: Decimal to Hexadecimal, vice
versa
Exercise: Convert 210D7A2 into its decimal form.
Chapter 2. Computer Number
Systems and Operations
BINARY ARITHMETIC
Chapter 2. Computer Number
Systems and Operations
Binary Arithmetic
Basic Rules
- 0+0=0
- 0+1=1
- 1+0=1
- 1+1=0 (with a carry over of 1)
Example:
100111
+ 1010
=110001
Exercise: Add the following binary numbers: 1011+1001=?
Chapter 2. Computer Number
Systems and Operations
Binary Arithmetic
Binary Subtraction:
- 0-0=0
- 1-0=1
- 1-1=0
- 0-1=1 (with a borrow of 1)
Example
101110
- 10000
=11110
Exercise: 10011110-1011101=?
Chapter 2. Computer Number
Systems and Operations
Binary Arithmetic
Binary Multiplication:
- 0x0=0
- 0x1=0
- 1x0=0
- 1x1=1
Exercise: 110x111=?
Exercise: 1100/100
Chapter 2. Computer Number
Systems and Operations
So, what’s the point?
Binary numbers are closely related to digital electronics.
Different parts of a computer communicate through pulses of current (1s
(on) and 0s (off))
Computer represents data in sets of binary digits. The representation is
composed of bits, which are then grouped into larger sets such as bytes.
All different types of information, from numbers, letters up to sound and
video can be represented using binary code.
Chapter 2. Computer Number
Systems and Operations
So, what’s the point?
In order for a human programmer to tell a computer (specifically its
microprocessor) what to do, he/she needs to write the instructions in the
CPU’s own language (machine language). This language is in binary
codes.
Example:
Hexadecimal Binary Instruction Description
7B 01111011 Move contents of register A to register B
Chapter 2. Computer Number
Systems and Operations
Why learn the other number systems?
In practice, writing out a binary number can be very tedious and prone to
errors.
Therefore, computer engineers often write binary quantities in octal or
hexadecimal number format. (Hexadecimal is more common)
Chapter 2. Computer Number
Systems and Operations