0% found this document useful (0 votes)
3 views

Introduction - Part 2

Uploaded by

aziz.khan01400j
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Introduction - Part 2

Uploaded by

aziz.khan01400j
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 39

Introductory Concepts on numerical

representations (Part 2)
Topic Outcome
• Analog and Digital representations

• Conversion between number systems – decimal, binary, octal and hexadecimal

• Number Operations – addition, subtraction using the different number systems


Analog and Digital

• We always deal with quantities

• Quantities are used to measure, monitor, record, observe and usually manipulated
arithmetically

• It is important that we are able to represent values efficiently and accurately

• Numerical value of quantities can be represented in two ways: ANALOG and


DIGITAL
Analog Representations

• In analog representation, a quantity is represented


by a voltage, current or meter movement that is
PROPORTIONAL TO THE VALUE OF THE
QUANTITY

• Analog quantities have an important characteristic:


they can vary over a continuous range of values

• Example: automobile speedometer, thermometer,


microphone (output voltage)
Digital Representations

• In digital representations, the quantities are represented not


by proportional quantities but by symbols called digits

• Example: digital watch

• Time of day changes continuously but watch reading does


not change continuously

• It changes by per second or per minute

• This means that digital representation of the time of day


changes in discrete steps
Differences

• Analog signals use a continuous range of values to represent the data and information

• Digital signals use discrete values (or discontinuous values), i.e. discrete 0 and 1, to
represent the data and information

• Digital representation:
• No ambiguity when reading the value of a digital quantity

• Analog representation:
• Open to interpretation
Digital and Analog Systems

• Digital system
• A digital system is a combination of devices designed to manipulate logical information or physical
quantities that are represented in digital form
• Digital devices are most often electronic

• Most familiar digital systems are computers, calculators, digital audio and video equipment, and
the telephone system – the world’s largest digital system
Digital and Analog Systems

• Analog System
• An analog system contains devices that manipulate physical quantities that are represented in
analog form
• The quantities can vary over a continuous range of values

• Example: the amplitude of the output signal to the speaker in a radio receiver can have any value
between zero and its maximum limit
• Other examples: light dimmer, audio amplifiers, magnetic tape
Number Systems and Operations

• Binary to Decimal
• Using the positional value of each digit, we can calculate the decimal expression of a binary number:

• For example:

• 101012 = 1 * 16 + 0 * 8 + 1 * 4 + 0 * 2 + 1 * 1

= 16 + 0 + 4 + 0 + 1

= 2110

128 64 32 16 8 4 2 1
0 0 0 1 0 1 0 1
Number Systems and Operations

• Decimal to Binary
• Repeatedly divide by 2; 2 ) 28
• For example: 2 ) 14 0
2 ) 7 0
• 2810
2 ) 3 1
2 1 1

• In the algorithm above, the result ing binary number should be read upside down.

• Therefore: 2810 = 111002

128 64 32 16 8 4 2 1
0 0 0 1 1 1 0 0
Number Systems and Operations
• Hexadecimal to Binary
• Hexadecimals are more convenient for human beings, and it is very easy to convert
between them and binary.

• To convert hexadecimal to binary, write each hexadecimal digit as a 4-bit binary


number and put it all together as in the following example:
Hexadecimal F D 6 9 A
Binary 1111 1101 0110 1001 1010

• The binary expression of $FD69A is %11111101011010011010. In particular, since a


byte is 8 bits, each memory location may be represented by 2 hexadecimal digits.

1111 1101 0110 1001 1010


F D 6 9 A
Number Systems and Operations
• Binary to Hexadecimal
• From binary to hexadecimal we break down the binary number into groups of 4 binary bits (padding with 0s to the left if
necessary), as in:

Binary 0101 1110 1010 1011 1111 0001


Hexadecimal 5 E A B F 1

• NOTE: Start at the right hand end and fill the left hand end with zeros to get 4 bits if necessary.
Number Systems and Operations
• Between Octal and Binary Binary Octal
Number Number
• These conversion are the same as the hexadecimal conversions, but instead of dividing
000 0
into groups of 4 you have to divide into groups of 3.
001 1
• For example:
010 2
• 111 001 101 1002 = 71548
011 3
111 001 101 100 100 4
7 1 5 4 101 5
110 6
111 7
Number Systems and Operations
• Decimal Addition
• To add in decimal, we learn some rules that are appropriate for that number system, such as

2 + 3 = 5 and 7 + 6 = 13.
5 6
+ 9 7
• Using these rules we have learnt how to add multi-digit numbers such as:
1 5 3

• When we add 6 + 7 we obtain 13, so we write down a sum of 3 and a carry of 10 to the next column:

• 56 + 97 = 50 + 6 + 90 + 7

= 50 + 90 + 6 + 7

= 50 + 90 + 13

= 50 + 90 + 10 + 3

= 150 + 3

= 100 + 50 + 3

= 153
Number Systems and Operations
• Binary Addition
• The rules are the same as for decimals, but remembering that 1 + 1 = 10, so when adding 1 + 1 you have to write down 0
and carry 1. Sum Carry
0+0= 0 0
0+1= 1 0
1+0= 1 0
1+1= 0 1

• Example: 1 0 1 0 = 1010
+ 00 01 10 1 = 0310
0 1 1 0 1 = 1310
Number Systems and Operations
• Data Sizes
• Computers deal with data in a fixed number of bits, 8, 16, 32, 64 bits Errors may occur when these sizes are exceeded

• For example, in 1001 1101 + 1000 1001 = 1 0010 0110 the leftmost bit (in bold) of the result is a carry out bit

• The result of the operation does not fit into 8 bits

• If we don’t consider the carry out bit, this operation is (in decimal):
• 157 + 137 = 38 which is clearly wrong

• The carry out bit is telling us that the result exceeds the 8 bits capacity, and that the result is not valid

NOTE: For unsigned data (more on this later), if the carry out bit is 1 the result is invalid
Number Systems and Operations
• Decimal Subtraction
• Consider the operations: 7 73
–4 –17
— —
+3 56

• The left hand side presents no problems

• On the right hand column of the second example we have 3 – 7 which we can’t do. So, we add the base 10 to the 3 to
give 13 producing a borrow of one to the next column (that is, an actual borrow of 10), and then subtract the 7 to give a
difference of 6
Number Systems and Operations
• Decimal Subtraction
• What we are actually doing is:

73 = 70 + 3
60 + 13
– 10 – 7
= 50 + 6 = 56
Number Systems and Operations
• Binary Subtraction Table: Binary Subtraction Rules Table

• Similarly, we can subtract binary


numbers — remembering that all
the operations are binary — like
so:

1 21 x 2 23
1 0 1 1 = 1110 -------
01 x 2 3 + 0 x 2 2 + 1 x 2 1 + 1 x 2 0 = 11 10
- 01 1 1 0 = 610 - 0 x 23 + 1 x 22 + 1 x 21 + 0 x 20 = 6 10
0 1 0 1 = 510 0 x 23 1 x 22 0 x 21 1 x 20 = 5 10
Number Systems and Operations
• Binary Subtraction
NOTE:

• The top number is larger than the bottom number. Since we are at the moment dealing with only positive numbers
(unsigned), it is not possible to subtract a larger number from a smaller one. If we do, the result will be invalid

• The need to borrow is indicated by the single 1 at the top, and the little 1 on the right-hand side of the last column

• A borrow out of the last column indicates that the top number is smaller than the bottom number, and so the result is
invalid
Number Systems and Operations
• Hexadecimal Addition
• By memorising the addition of hexadecimal digits, we can add hexadecimals. Similar to base 10, this is the ‘add tables’
in the base 16. 3+5= 8 5+5= A
3+6= 9 5+8= D
3+7= 7+8=
3+8= 8+8=
A+3= A+4=
A+5= A+6=
B+7= D+8=

• We have to memorise hexadecimal addition tables

• Exercise: complete the table


Number Systems and Operations
15 + 2 = 17 > 16 12 +10 = 22 > 16
• Hexadecimal Addition
17 – 16 = 1 22 – 16 = 6
•Example:
1 1
$ 1 F 4 C 3 = 12819510 $ 1 15 4 12 3 = 12819510
+ $ 7 2 9 A B = 46941910 + $ 7 2 9 10 11 = 46941910
9 1 E 6 E = 59761410 9 1 E 6 E = 59761410

•316 +B 16 = E16 and carry = 0


•C16 +A 16 = 1616 sum 616 and carry = 1
Number Systems and Operations
• Hexadecimal Multiplication
• We can also construct multiplication (times) tables:

Table: Some hex operations:


2*3=6 2 * 8 = 10 2*D=
2*4=8 2 * 9 = 12 2*E=
2*5=A 2 * A = 14 2*F=
2*6=C 2*B= 3*8=
2*7=E 2*C= 3*A=
Number Systems and Operations
• Hexadecimal Subtraction
• By remembering the addition rules of hexadecimal digits, subtraction is straightforward. Consider the following example shown.

• When the top hex digit is too small, we do the same as in decimal arithmetic. For example, for the final column we have:

B16 - 916 = 216 and borrow = 0


516 - A16 = B16 and borrow = 1
F16 - 316 - 116 (the borrow) = B16 1 x 16 2 = 256

161xx16
1612
$ F 5 B = 393110 -------
E
F x 16 22 + 5 x 16 1 + B x 16 0 = 393110
- $ 3 A 9 = 93710 - 3 x 16 2 + A x 16 1 + 9 x 16 0 = 93710
B B 2 = 299410 B x 16 2 B x 16 1 5 x 16 0 = 299410
Number Systems and Operations
• Binary Numbers Range
Table: N o of bits vs. Range
Bits Range/Max Value No of values
8 0 - 255 256
16 0 - 65,335 65,536
32 0 - 4,294,967,295 232
64 0 -18,446,744,073,709,551,615 264

• The maximum value is 2n -1, i.e. for 8 bit s it is 28 -1 = 255


Number Systems and Operations
• Binary Addition
• 1010 + 1101 =

• Binary Subtraction
• 1100 – 1010 =

• Hexadecimal Addition
• ADD + DDA =

• Hexadecimal Subtraction
• A4B – 87C =
Exercise
• Binary Addition Sum Carry
0+0= 0 0
• 1010 + 1101 0+1= 1 0
1+0= 1 0
1+1= 0 1

1 0 1 0 = 1010
+ 1 1 0 1 = 1310
1 0 1 1 1 = 2310
Exercise
• Binary Subtraction
• 1100 - 1010

1 x 22= 4

12 x 2 21
1 1 0 0 = 1010 01 x 2 2
1 x 2 3 + ------- + 0 x 21 + 0 x 20 = 12 10
- 1 0 1 0 = 1210 - 1 x 23 + 0 x 22 + 1 x 21 + 0 x 20 = 10 10
0 0 1 0 = 210 0 x 23 0 x 22 1 x 21 0 x 20 = 2 10
Exercise
• Hexadecimal Addition
1 + 13 + 13 = 27 > 16
• ADD + DDA =
1 + 10 + 13 = 24 > 16 27 – 16 = 11 13 +10 = 23 > 16
23 – 16 = 7 23 – 16 = 7

$ A D D = 278110 1 1 1
$ 10 13 13 = 278110
+ $ D D A = 354610
+ $ 13 13 10 = 354610
1 8 B 7 = 632710
1 8 B 7 = 632710
Exercise
• Hexadecimal Subtraction
1 x 16 2 = 256
• A4B – 87C

1 x 16 1 = 16

116xx16162 1 16
1 xx16
161 0
$ A 4 B = 263510 9------
A xx 16
1622 + 3-------
4 xx 16
1611 + B x 16 0 = 263510
- $ 8 7 C = 217210 - 8 x 16 2 + 7 x 16 1 + C x 16 0 = 217210
1 C F = 46310 1 x 16 2 C x 16 1 F x 16 0 = 46310
Binary Coded Decimal (BCD)
• Would it be easy for you if you can replace a decimal number with an individual binary code?
• Such as 00011001 = 1910

• The 8421 code is a type of BCD to do that.

• BCD code provides an excellent interface to binary systems:


• Keypad inputs

• Digital readouts
Binary Coded Decimal (BCD)
Decimal
0 1 2 3 4 5 6 7 8 9
Digit

BCD 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001

• Note: 1010, 1011, 1100, 1101, 1110, and 1111 are INVALID CODE!

• For example, Decimal to BCD = 3510 = 0011 0101BCD

• For example, BCD to Decimal = 10000110BCD = 8610


Binary Coded Decimal (BCD)
Decimal
0 1 2 3 4 5 6 7 8 9
Digit

BCD 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001

• For example, BCD to Binary = 1000 0110BCD

1) Convert the BCD to Decimal = ?10

2) Convert Decimal to Binary = ?2


Binary Coded Decimal (BCD)
Decimal
0 1 2 3 4 5 6 7 8 9
Digit

BCD 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001

• For example, Binary to BCD = 10001112

1) Convert the Binary to Decimal = 100 0111 = 4710

2) Convert Decimal to BCD = 0100 0111BCD


Binary Coded Decimal (BCD) - Addition
• BCD Addition
NOTE:

• BCD is a numerical code and can be used in arithmetic operations. Here is how to add two BCD numbers:

• Add the two BCD numbers, using the rules for basic binary addition.

• If a 4-bit sum is equal to or less than 9, it is a valid BCD number.

• If a 4-bit sum > 9, or if a carry out of the 4-bit group is generated it is an invalid result. Add 6 (0110) to a 4-bit sum in
order to skip the six the invalid states and return the code to 8421. If a carry results when 6 is added, simply add the
carry to the next 4-bit group.
Binary Coded Decimal (BCD) - Addition
Decimal
0 1 2 3 4 5 6 7 8 9
Digit

BCD 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001

• BCD Addition, 0010 + 0110 • BCD Addition, 0011 + 0111


1 1 1 1 1
0 0 1 0 = 210 0 0 1 1 = 310
+ 0 1 1 0 = 610 + 0 1 1 1 = 710
1 0 0 0 = 810 Valid BCD 11 0 1 1 0 = 1010 Invalid in BCD
+ 0 1 1 0 = 610
1 0 0 0 0 = 1610

0001 0000
Valid in BCD
1 0
Exercise
• BCD Addition

• 5710 + 26 10
Exercise
• Binary Addition

• 5710 + 26 10
1 1
0 1 0 1 0 1 1 1 = 5710
+ 0 0 1 0 0 1 1 0 = 2610
1 1 1 1 1
0 1 1 1 1 1 0 1 = 8310 Invalid in BCD
+ 0 1 1 0 = 610
1 0 0 0 0 0 1 1 = 8910

1000 0011
Valid in BCD
8 3
Next Topic
Number Systems and Code: Conversion between Number Systems

THANK YOU

You might also like