0% found this document useful (0 votes)
4 views29 pages

Lecture 4 - The Digital Logic Level, Part 3

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views29 pages

Lecture 4 - The Digital Logic Level, Part 3

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 29

Lecture 3: The Digital

Logic Level – Introduction

Foundations of Computing
To Binary Numbers
Foundations of Computing: Technical Strand
João Filipe Ferreira

1
Numeral Systems

Foundations of Computing
The words ‘digital’ and ‘digit’ come from the latin
word ‘digitus’, which means finger

Our first biological truly digital calculator!


dactylonomy (noun)
the practice of counting using fingers
3
Numeral Systems

Foundations of Computing
the Ishango bones (30,000 BCE!)
European tally marks (w/ clustering)
tally marks – unary numeral system

counting 4
Numeral Systems
Roman Numerals
(from 900 BCE until Middle Ages)

ancient numbers

non-positional, sign-value system!


i.e. positions have no absolute weight,
only relative (left to right)
counting 5
Numeral Systems
the evolution of the Indo-Arabic numeral system

Foundations of Computing
counting 6
Numeral Systems
the evolution of the Indo-Arabic numeral system

Foundations of Computing
counting 7
Numeral Systems
the evolution of the Indo-Arabic numeral system

Foundations of Computing
counting 8
Numeral Systems
the evolution of the Indo-Arabic numeral system

Foundations of Computing
counting 9
Numeral Systems
the evolution of the Indo-Arabic numeral system

positional system
(i.e. it uses a place-value notation)

counting 10
Numeral Systems
positional system
(i.e. it uses a place-value notation)
bit= binary digit
162 161 160 16-1 16-2

A B C

binary decimal hexadecimal


weights are powers of 2 weights are powers of 10 weights are powers of 16
only two digits possible (0,1) only 10 digits possible (0 to 9) only 16 digits possible (0 to F)

counting numbers
Numeral Systems
• When we use numbers in every day life we write them using a
specific set of numbers (symbols) in a positional number
system:
• We use the decimal number system (base 10)
• Numbers range between 0 to 9
• Different positions n signify different weights (10n)

Foundations of Computing
• e.g. Take for instance: 12,687 1 2 6 8 7
Each position signifies a different

10000’s

1000’s

1’
10’
100’

s
s
weighting (each position is 10 times the
previous)
Position 5 4 3 2 1
Weight (base 10) 10000 1000 100 10 1
Decimal number 1 2 6 8 7
 12
 Weight
n 0
n * digit n  (10000 *1)  1000 * 2  100 * 6  10 * 8 1* 7 

1268710 The radix is specified in subscript


to indicate the base
Other Computing-Related
Numeral Systems
• As we saw on the previous slide, decimal uses a base 10 number system
(each column position has a weight that is 10x the previous)
• However, there are other number systems (using different bases) which
you will encounter when analysing and using computing devices:
• Binary: - base 2 which means only 1 or 0 different values and each column

Foundations of Computing
weight is double the preceding one:
• e.g. 10112

• Hexadecimal: - base 16 which means there are 16 different values before


moving to the next column – 0 to 9 and A-F (i.e. each position weight is 16x the
previous):
• e.g. 12AC3E16 ( which is 122374210 in decimal)

• Octal: - base 8 which means there are 8 different values before moving to the
next column – 0 to 7 (i.e. each position weight is 8x the previous);
• e.g. 318 (which is 2510 in decimal – note that in this particular situation, 13
the use of the radix is essential!)

We will look at Binary now and Hexadecimal in the next lecture


Binary
• Binary is a base 2 number system:
• Digits can only be a 0 or 1
• Each position is twice the weight of the previous position
• All numbers can be represented as a pattern of 1’s or 0’s
For example:
Values are

Foundations of Computing
512 256 128 64 32 16 8 4 2 1
calculated by 2n
1 1 0 1 1 0 1 1 0 1
e.g. position weighting (2n)
20 = 1 º (1)
• In binary, this would be represented as: 1101101101
21 = 22 º (2)
• 22 =all
To work out what this is in decimal, we need to add 4 ºthe(2columns
x 2)
23 = 8 º (2 x 2 x 2)
with a “1” in them. 24 = 16 º (2 x 2 x 2 x2)
25 = 32 º (2 x 2 x 2 x 2 x 2)
Therefore,

14
 Weight n * digitn  (512 *1) (256 *1)(128 * 0)  (64 *1)  (32 *1)  (16 * 0)  8 *1 4 *1 2 * 0 1*1 87710
n 0
11011011012 87710
Converting from Decimal
• There are two ways of converting a number
from decimal to binary.
• Method 1: Division Method E.g. Convert 15510 to binary
• Steps / algorithm: 15510 / 210 = 7710 77.5 77(r 1)
1. Divide the decimal number by 2 (i.e. the

Foundations of Computing
7710 / 210 = 3810 38.5 38(r 1)
number base you want to convert to).
3810 / 210 = 1910 19 19(r 0)
2. If there is a fraction left over (i.e. 0.5) then
set remainder bit (r) to 1, otherwise (i.e. no 1910 / 210 = 910 9.5 9(r 1)
fraction left over), set remainder bit (r) to 0. 910 / 210 = 410 4.5 4(r 1)
3. Set new decimal number to the lowest
410 / 210 = 210 2 2(r 0)
whole number from the division
4. If decimal number not equal to 0, repeat 210 / 210 = 110 1 1(r 0)

step 1, otherwise finish. 110 / 210 = 010 0.5 0(r 1)


• To see the binary conversion, need to read 15
From bottom to top we
from bottom to top. get: 100110112
Converting from Decimal
• There are two ways for converting a number from decimal to
binary.
• Method 2: Subtraction Method
• Example: convert 17210 to binary

Foundations of Computing
128 64 32 16 8 4 2 1 172 – 128 = 44 (set r = 1)
44 – 64 = -ve number (set r = 0)
1 0 1 0 1 1 0 0
44 – 32 = 12 (set r = 1)
12 – 16 = -ve number (set r = 0)
17210 = 101011002 12 – 8 = 4 (set r = 1)
MSB LSB 4 – 4 = 0 (set r = 1)
(most significant bit) (least significant bit)
0 – 2 = -ve number (set r = 0)
0 – 1 = -ve number (set r = 0) 16

(+ve shorthand for positive; -ve shorthand for negative)


Quick Exercise…
• Use the subtraction method to work out the following decimal
to 13-bit binary conversions:
• 192010 to binary
• 730910 to binary

Foundations of Computing
• 10010 to binary
• 231710 to binary
• 58910 to binary
• Use the following grid to help you in your workings…
4096 2048 1024 512 256 128 64 32 16 8 4 2 1

17
Unsigned Binary Integers
• In the decimal system, the term unsigned denotes positive whole numbers
• Therefore, an unsigned binary number would also represent a positive
whole number
• The range of values are between (0 < x < 2 n -1) where n is the number of bits
• Some terminology:

Foundations of Computing
• bit = a single 1 or 0 binary digit
• bits = multiple 1 or 0 bits
• nibble = 4 bits
• Byte = 8 bits
• Word = number of bits a CPU can process in one go (e.g. Intel Core i7 = 64 bits)

• For example - an 8 bit number can be between 0 and a maximum:


• (number of bits) n = 8
• Minimum: 0000 00002 = 010
• Maximum: 1111 11112 = 25510 = 28 -1
18
• Therefore, all positive unsigned values can be represented in this fashion
• However, how do we represent negative numbers?
Signed Binary Integers
• Signed binary numbers represent both positive
and negative whole numbers
• The full range of values can be represented as (-2n-1-1 < x < +2n-1 -1)
where n is the number of bits
• The most significant bit represents the ‘negative symbol’

Foundations of Computing
• For example: 8 bit numbers
• Number of bits, n = 8 128
-/+ 64 32 16 8 4 2 1

However, bit 8 (MSB) represents 1 or 0 to


We can only store 7 bits
indicate positive (0) or negative (1)
of information.
19
Minimum value: 1111 11112 = -12710 = -27-1
Maximum value: 0111 11112 = 12710 =27-1
Binary sums
• We can use signed binary integer notation to represent both
negative and positive numbers
• We can perform standard operations with this notation:
• Addition
• Subtraction

Foundations of Computing
• Multiplication
• However, we seem to be able to represent both
a positive and a negative 0:
• 1000 00002 = -010, 0000 00002 = +010
• Can we add/subtract with this oddity with 0?
• Answer: to perform these operations we need to be aware of
one’s and two’s complement 20
One’s Complement
• As unsigned numbers can be +ve or –ve,
using one’s complement removes the positive and negative 0
problem from binary signed integers
• Lets say we need to represent a negative number…
• In this case, we have to invert all of the binary digits:

Foundations of Computing
• + 1110 = 0000 10112
• - 1110 = 1111 01002
• However, this introduces a problem for addition:
• An overflow bit must be wrapped around as a carry bit
• Example: 1310 + (-210)
00001101
11111101+ 21
Overflow bit 100001010 Carry bit
1+
00001011 = 1110
Two’s Complement (i)
• Overflow issue in one’s complement is problematic
• It slows down addition
• It is complex to implement in hardware
• Two’s complement removes the need for the overflow carry

Foundations of Computing
• However we need to work with a fixed precision (e.g. 8 bits)
rather than taking shortcuts

• To convert a positive number to a negative number:


• Invert all of the binary digits
• + 1110 = 0000 10112
• = 1111 01002
• Then add one (+12)
22
• -1110 = 1111 01012
Two’s Complement (ii)
• Two’s complement numbers represent positive
and negative whole numbers
• Range: (-2n-1 < x < +2n-1 -1) where n is the number of bits
• Most significant bit still represents the ‘negative symbol’ however the
value is negative

Foundations of Computing
• Think of the weights as:
Position 8 7 6 5 4 3 2 1
Weight (base 10) -128 64 32 16 8 4 2 1

• Example: 8 bit numbers


• N=8 23
• Minimum: 1000 00002 = -12810 = -27
• Maximum: 0111 11112 = 12710 = 27-1
Basic Binary Addition (i)
• Binary addition is not the same as an OR operation!
• 2 bit binary addition follows four basic rules:
• 02 + 02 = 010 = 002
• 02 + 12 = 110 = 012

Foundations of Computing
• 12 + 02 = 110 = 012
1 1
• 12 + 12 = 210 = 102 1
0
0 1 0 1
1 +
0
0 1 0 0 +
0
1
• Example: 510 + 410 = 910 1 0 0 1 1
0

0000 0101
0000 0100+
0000 1001 24
Basic Binary Addition (ii)
Carry bit
• Handling overflow:
1
• Consider the carry example in the last slide 0 1 0 1
• 110 + 110 = 210 = 102 0 1 0 0
1 0 0 1
• What if those bits were 1’s? 1 1

Foundations of Computing
0 1 1 0 1 1
• We need 1 more bit (or overflow)
0 1 1 0 0 1 +
• 110 + 110 + 110 = 310 = 112
1 1 0 0 1 1
1
Carry bits
• ... and higher values? 1 0 1
0 0 1 0 0 0 1
(adding 3+ numbers at once) 1
• 110 + 110 + 110 + 110 = 410 = 1002 0 0 1 1 0 1 1
0 0 1 1 0 0 1 +
• Write the carry in one place at a time.
1 0 0 0 0 1 0 25
10
Two’s Complement Addition
• Uses the same ‘tricks’ as binary addition however must use a
fixed length.
• Example: -5310 + 7810 as 8 bit binary numbers
• +7810 = 0100 11102

Foundations of Computing
• +5310 = 0011 01012
• -5310 = 1100 10112 (invert the bits and add one)

7810 010011102 Addition not subtraction


5310- 110010112+ 7810 + (-5310)
2510 1000110012

Overflow bit is ignored

• Therefore, 000110012 = 2510 26

Example 2: -2110 + 4110


Two’s Complement
Subtraction
• Is the same as addition

• Example: 4510 – 2510 = 4510 + (-2510)

• With two’s complement addition and subtraction are the same

Foundations of Computing
27
Binary Multiplication (i)
• Binary multiplication is:
• Multiple additions
• Shifting the number
10112 1110
Current bit is: 1
0

Foundations of Computing
11012 x 1310
Add the value: 11012 11012
Add the value: 11012 11010 2 Shift left one position

000000 2 Shift left one position


Add the value: 11012
1101000 2  Shift left one position
28
10001111 2 14310
Homework questions
Use Binary Arithmetic to solve the following:

Addition: 6410 + 3110

Addition: 6610 + 3110

Foundations of Computing
Subtraction: 6410 - 3110

Multiplication: 1110 * 510

29
Summary
• In this lecture we have looked at:
• Decimal & Binary numeral systems
• One’s & Two’s complement
• Binary arithmetic:
• Addition

Foundations of Computing
• Subtraction
• Multiplication

Directed Study
1. Read Appendix A (Binary Numbers) & B (Floating Point
Numbers) - 6th Edition, Structured Computer Organisation.
Investigate
2. Floating point numbers. 30
3. Hexadecimal numbers.

You might also like