You are on page 1of 93

Number System

(Different Ways To Say How Many)

Fall 2019
2 Outline
 Numeral System
 Decimal System
 Binary System
 Octal System
 Hexadecimal System
 Digit and Positions
 Bits, Bytes & Words
 Conversions
 Negative Numbers
 Boolean Logic Operations
11/11/2019
Numeral System
3

A Numeral System is a writing-system for expressing


numbers, a mathematical notation for representing
numbers of a given set, using symbols in a consistent
manner.
Ideally, a numeral system will:
Represent a useful set of numbers (integers, or rational numbers)
Give every number represented a unique representation (or a
standard representation)
Reflect the algebraic and arithmetic structure of the numbers.

11/11/2019
4 Base/Radix of Numeral System
The number of distinct symbols that can be used to represent
numbers in that system.
For example, the base for the „decimal numerical symbol is 10‟,
as we can use the ten symbols 0,1,2,…,9 to represent numbers
in this system.

This means that the same number will have different


representations in different systems. So, ‘101’ means
a hundred and one in decimal, and five, in binary;
while 5 means five in decimal but is invalid in
binary as the symbol ‘5’ is not allowed in binary.

11/11/2019
5 Decimal Number System
The decimal numeral system (base ten or denary) has
ten as its base. It is the numerical base most widely used
by modern civilizations.

11/11/2019
Binary Number System
6

 The binary numeral system (base two) has two as its base.
 It is the numerical base used by the modern day computers where
numbers need to be stored using the on/off logic of electronic and/or
magnetic media. The ON and OFF conveniently translate into 1 and 0.

11/11/2019
7 Octal Number System
base eight) has eight as its base.
 The octal numeral system (

11/11/2019
Hexadecimal Number System
8
 The hexadecimal numeral system (base 16) has sixteen as its base.
 This system uses the 16 symbols: {0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F}
 The main advantage of using this numeral system is that it keeps the
representations short, and hence manageable.
 For example: the decimal number 199834, is represented in binary as
110000110010011010; and in hexadecimal as 30C9A.

11/11/2019
9
Why we need all these systems

 The length of representations can grow very rapidly in binary, and


even decimal, while slowly in hexadecimal, as extra symbols are
allowed.
 So we need hexadecimal to keep things manageable on the paper.
 Computers need binary numbers, but humans can work better with
decimal, octal and hexadecimal.
 Hence we should know all these systems and how to convert numbers
between these different representations.

11/11/2019
10 Digit & Position
 The length of a representation grows, from right to left, like: 0,1, 2, 3, … so
on.
 Let‟s take the example of the decimal system.
 The number nine, in decimal, consists of one digit „9‟ at position 0.
 Similarly, all the numbers 0, 1, 2…,9 all consist of a single digit at position 0.
 But once we reach 9, we have run out of new symbols (in decimal system) and
hence we must increase the length.
 Therefore we add another digit to the left, at position 1. Hence we get 10,
11,12…,19,20,21,…,99.
 when again, we run out of all length-two combinations of symbols and must proceed
to length-three representations, starting from 100, so on.
11/11/2019
Digit & Position
11

In general, a number x may be represented with a


representation of length n in the following manner (here dp
means the digit at position p).

dn-1 … d3 d2 d1 d0

So for the number 199834, in decimal, d0=4, d1=3, d2=8, d3=9,
d4=9 and d5=1.
In general, We call the rightmost digit, d0, the least significant
digit (LSB)
and the leftmost digit dn-1, the most significant digit (MSB).

11/11/2019
BITS, BYTES and WORDS
12
A digit in the binary system is more commonly called a bit.
Therefore, a bit is a single digit in the binary representation of a
number and is either 0 or 1.
When a binary number is represented using 8 bits, the resulting
representation, composed of d0, d1, d2… d7, is called a byte.
Similarly a binary representation composed of 16 bits is called a
word,
a binary representation composed of 32 bits is called a double
word,
and a binary representation composed of 64 bits is called a
quadruple word.
11/11/2019
BITS, BYTES and WORDS
13

A less common, 4-bit representation of numbers is called


nibble.
The concept of a byte is fundamental in computer science
because a byte is the smallest addressable unit of memory in
a modern computer; furthermore, data is quantified in terms of
byte!
When you say that your hard-disk can store 20 Giga Bytes, you
really mean that it can store 20x230 bytes of data.
A byte is therefore a unit for measuring data in computers.

11/11/2019
BITS, BYTES and WORDS
14

The following quantifiers are important:


KILO
1K = 210 So how many bytes in 37KB?
MEGA
1M = 220 So how many Kilo bytes in 137MB?
GIGA
1G = 230 So how many Tera bytes in 562MB?
TERA
1T = 240 So how Giga bytes in 307TB?
11/11/2019
Conversion Among Bases
 The possibilities:

Decimal Octal

Binary Hexadecimal

11/11/2019
Quantities/Counting (1 of 3)
Hexa-
Decimal Binary Octal decimal
0 0 0 0
1 1 1 1
2 10 2 2
3 11 3 3
4 100 4 4
5 101 5 5
6 110 6 6
7 111 7 7
Quantities/Counting (2 of 3)
Hexa-
Decimal Binary Octal decimal
8 1000 10 8
9 1001 11 9
10 1010 12 A
11 1011 13 B
12 1100 14 C
13 1101 15 D
14 1110 16 E
15 1111 17 F
Quantities/Counting (3 of 3)
Hexa-
Decimal Binary Octal decimal
16 10000 20 10
17 10001 21 11
18 10010 22 12
19 10011 23 13
20 10100 24 14
21 10101 25 15
22 10110 26 16
23 10111 27 17
Quick Example

2510 = 110012 = 318 = 1916


Base

11/11/2019
Decimal to Decimal (just for fun)

Decimal Octal

Binary Hexadecimal

11/11/2019
Weight

12510 => 5 x 100= 5


2 x 101 = 20
1 x 102 = 100
125

Base

11/11/2019
Binary to Decimal

Decimal Octal

Binary Hexadecimal

11/11/2019
Binary to Decimal

Technique
Multiply each bit by 2n, where n is the “weight” of the bit
The weight is the position of the bit, starting from 0 on the
right
Add the results

11/11/2019
Example
Bit “0”

1010112 => 1 x 20 = 1
1 x 21 = 2
0 x 22 = 0
1 x 23 = 8
0 x 24 = 0
1 x 25 = 32
4310

11/11/2019
Octal to Decimal

Decimal Octal

Binary Hexadecimal

11/11/2019
Octal to Decimal

Technique
n
Multiply each bit by 8 , where n is the “weight” of
the bit
The weight is the position of the bit, starting from 0 on
the right
Add the results
Example

7248 => 4 x 80 = 4
2 x 81 = 16
7 x 82 = 448
46810
Hexadecimal to Decimal

Decimal Octal

Binary Hexadecimal
Hexadecimal to Decimal

Technique
Multiply each bit by 16n, where n is the “weight” of
the bit
The weight is the position of the bit, starting from 0 on
the right
Add the results
Example

ABC16 => C x 160 = 12 x 1 = 12


B x 161 = 11 x 16 = 176
A x 162 = 10 x 256 = 2560
274810
Decimal to Binary

Decimal Octal

Binary Hexadecimal
Decimal to Binary

Technique
Divide by two, keep track of the remainder
First remainder is bit 0 (LSB, least-significant bit)
Second remainder is bit 1
Example
2 125
12510 = ?2
2 62 1

2 31 0
15 1
2
7 1
2
2 3 1

2 1 1
0 1

12510 = 11111012
Octal to Binary

Decimal Octal

Binary Hexadecimal
Octal to Binary

Technique
Convert each octal digit to a 3-bit equivalent
binary representation
Example
7058 = ?2

7 0 5

111 000 101

7058 = 1110001012
Hexadecimal to Binary

Decimal Octal

Binary Hexadecimal
Hexadecimal to Binary

Technique
Convert each hexadecimal digit to a 4-bit
equivalent binary representation
Example
10AF16 = ?2

1 0 A F

0001 0000 1010 1111

10AF16 = 00010000101011112
Decimal to Octal

Decimal Octal

Binary Hexadecimal
Decimal to Octal

Technique
Divide by 8
Keep track of the remainder
Example
123410 = ?8

8 1234
8 154 2
8 19 2
8 2 3
0 2

123410 = 23228
Decimal to Hexadecimal

Decimal Octal

Binary Hexadecimal
Decimal to Hexadecimal

Technique
Divide by 16
Keep track of the remainder
Example
123410 = ?16

16 1234
16 77 2
16 4 13 = D
0 4

123410 = 4D216
Binary to Octal

Decimal Octal

Binary Hexadecimal
Binary to Octal

Technique
Group bits in threes, starting on right
Convert to octal digits
Example
10110101112 = ?8

1 011 010 111

1 3 2 7

10110101112 = 13278
Binary to Hexadecimal

Decimal Octal

Binary Hexadecimal
Binary to Hexadecimal

Technique
Group bits in fours, starting on right
Convert to hexadecimal digits
Example
10101110112 = ?16

10 1011 1011

2 B B

10101110112 = 2BB16
Octal to Hexadecimal

Decimal Octal

Binary Hexadecimal
Octal to Hexadecimal

Technique
Use binary as an intermediary
Example
10768 = ?16
1 0 7 6

001 000 111 110

2 3 E

10768 = 23E16
Hexadecimal to Octal

Decimal Octal

Binary Hexadecimal
Hexadecimal to Octal

Technique
Use binary as an intermediary
Example
1F0C16 = ?8
1 F 0 C

0001 1111 0000 1100

1 7 4 1 4

1F0C16 = 174148
Exercise – Convert ...
Hexa-
Decimal Binary Octal decimal
33
1110101
703
1AF

Don‟t use a calculator!

Skip answer Answer


Exercise – Convert
Answer …
Hexa-
Decimal Binary Octal decimal
33 100001 41 21
117 1110101 165 75
451 111000011 703 1C3
431 110101111 657 1AF
Exercise – Convert ...
Hexa-
Decimal Binary Octal decimal
29.8
101.1101
3.07
C.82
Don‟t use a calculator!

Skip answer Answer


Exercise – Convert
Answer …
Hexa-
Decimal Binary Octal decimal
29.8 11101.110011… 35.63… 1D.CC…
5.8125 101.1101 5.64 5.D
3.109375 11.000111 3.07 3.1C
12.5078125 1100.10000010 14.404 C.82
Converting numbers from other bases
62
to their decimal equivalents

Binary 1001 (so r=2) : Hexadecimal 12AC (so r=16):


D = 1x20+0x21+0x22+1x23 D = Cx160+Ax161+2x162+1x163
= 1+0+0+8 = 12+160+512+4096
=9
= 4780
Octal 1767 (so r=8) :
D = 7x80+6x81+7x82+1x83 (A represents a decimal 10 and
= 7+48+448+512 C represents a decimal 12)
= 1015
11/11/2019
63
Sources
 [1] http://en.wikipedia.org/wiki/Numeral_systems
 [2] https://www.mathsisfun.com/numbers/index.html
 [3] http://atrevida.comprenica.com/atrtut01.html
 [4] https://indepth.dev/the-simple-math-behind-decimal-binary-conversion-algorithms/

11/11/2019
Negative Number
64

How to represent negative number in binary system


Signed Magnitude
1‟s Complement
2‟s Complement

11/11/2019
65
Signed Magnitude
Use the leftmost digit as a sign indication,
and treat the remaining bits as if they represented an
unsigned integer.
The convention is that if the leftmost digit (most significant
bit) is 0 the number is positive,
if it‟s 1 the number is negative.

00001010 = decimal 10
10001010 = decimal -10

11/11/2019
Signed Magnitude
66

The main problem with this system is that it doesn‟t support


binary arithmetic (which is what the computer would naturally
do).
That is, if you add 10 and -10 binary you won‟t get 0 as a result.
00001010 (decimal 10)
+ 10001010 (decimal -10)
_____________________
10010100 (decimal -20)

11/11/2019
67
1’s Complement
 To obtain one‟s complement, you simply need to flip all the bits.
 Suppose we are working with unsigned integers.
 Decimal 10 is represented as: 00001010
 It‟s one complement would be: 11110101
 Notice that the complement is 245, which is 255 – 10.
 That is no co-incidence.
 The complement of a number is the largest number represented with the
number of bits available minus the number itself.
 Since we are using 8 bits here the maximum number represented is 255 (2^8 – 1). So
the complement of 10 will be 245.

11/11/2019
1’s Complement
68

using the one‟s complement system to represent negative


numbers.
we would have two representations of zeroes:
00000000 (could be seen as +0)
and 11111111 (could be seen as -0).
00001100 (decimal 12)
+11110011 (decimal -12)
____________________
11111111 (decimal -0)
11/11/2019
69
1’s Complement
this system partially solves the binary arithmetic problem
because there are some special cases left.
00000011 (decimal 3)
+11111101 (decimal -2)
-------------
100000000 (decimal 256)
But since we have only 8 bits to represent the numbers, the
leftmost 1 will be discarded,
and the result would be 00000000 (decimal +0).
This is not the answer we expected.
11/11/2019
2’s Complement
70

Two‟s Complement of a binary number is basically


another number which, when added to the
original, will make all bits become zeroes.
You find a two‟s complement by first finding the
one‟s complement, and then by adding 1 to it.
 11110011 (one's complement of 12)
+00000001 (decimal 1)
 -------------
 11110100 (two's complement of 12)
11/11/2019
71
2’s Complement
Now let‟s add 12 with -5 to see if we‟ll have the
same problem that we had when using the one‟s
complement system:
00001100 (decimal 12)
+11111011 (decimal -5)
-------------
00000111 (decimal 7)

11/11/2019
72

11/11/2019
Number Overflow
73

Overflow occurs when the value that we compute


cannot fit into the number of bits we have allocated
for the result.
For example, if each value is stored using eight bits,
adding 127 to 3 would overflow:
 01111111
+ 00000011
---------------
 10000010

11/11/2019
74
Number Overflow
 Overflow occurs when the value that we compute cannot fit into
the number of bits we have allocated for the result.
 For example, if each value is stored using eight bits, adding127 to 3
would produce an overflow:

 In our scheme 10000010 represents –126, not +130.


 If, however, we were not representing negative numbers, the
result would be correct.
11/11/2019
Code for Letters and Symbols
75

Computers use a standard binary code to represents


letters of the alphabet, numerals, punctuation marks
and other special characters.
The code is called ASCII (pronounced “askey”) which
stands for “American Standard Code for Information
Interchange.”
There are 256 code combinations.

11/11/2019
Boolean Logic Operations
Let x, y, z be Boolean variables.

Boolean variables can only have binary values i.e.,


they can have values which are either 0 or 1

For example, if we represent the state of a light switch with a


Boolean variable x, we will assign a value of 0 to x when the
switch is OFF, and 1 when it is ON
A few other names for the states of these Boolean variables

0 1

Off On

Low High

False True
We define the following logic operations or
functions among the Boolean variables

Name Example Symbolically


NOT y = NOT(x) x´
AND z = x AND y x·y
OR z = x OR y x+y
XOR z = x XOR y xy
We‟ll define these operations with the help of truth tables

what is the truth table of a logic


function
?
A truth table defines the output of a logic
function for all possible inputs
Truth Table for the NOT Operation
(y true whenever x is false)

x y = x´
0
1
Truth Table for the NOT Operation

x y = x´
0 1
1 0
Truth Table for the AND Operation
(z true when both x & y true)

x y z=x·y
0 0
0 1
1 0
1 1
Truth Table for the AND Operation

x y z=x·y
0 0 0
0 1 0
1 0 0
1 1 1
Truth Table for the OR Operation
(z true when x or y or both true)

x y z=x+y
0 0
0 1
1 0
1 1
Truth Table for the OR Operation

x y z=x+y
0 0 0
0 1 1
1 0 1
1 1 1
Truth Table for the XOR Operation
(z true when x or y true, but not both)

x y z=xy
0 0
0 1
1 0
1 1
Truth Table for the XOR Operation

x y z=xy
0 0 0
0 1 1
1 0 1
1 1 0
Those 4 were the fundamental logic operations. Here are
examples of a few more complex situations

z = (x + y)´

z = y · (x + y)

z = (y · x)  w

STRATEGY: Divide & Conquer


z = (x + y)´
x y x + y z = (x + y)´
0 0 0 1
0 1 1 0
1 0 1 0
1 1 1 0
z = y · (x + y)
x y x + y z = y · (x + y)
0 0 0 0
0 1 1 1
1 0 1 0
1 1 1 1
z = (y · x)  w
x y w y · x z = (y · x) 
w
0 0 0 0 0
0 0 1 0 1
0 1 0 0 0
0 1 1 0 1
1 0 0 0 0
1 0 1 0 1
1 1 0 1 1
1 1 1 1 0
Assignment# 1
93

1. What are three differences between a Mainframe Computers


computer and a Supercomputers computer, explain with
examples/reasons? (5)
2. Explain the three parts of an E-Mail Addresses with examples? (5)
3. Artificial Intelligence is an area of Computer Science concerned with
making the computer perform tasks which, to be successfully done by
human beings, require intelligence, and Artificial intelligence (AI) forms
an intrinsic aspect of the competence of fifth generation computers.
Describe AI - How computer learn, data mining, expert system and
Robotics. (10).

11/11/2019

You might also like