Introduction - Part 2
Introduction - Part 2
representations (Part 2)
Topic Outcome
• Analog and Digital representations
• Quantities are used to measure, monitor, record, observe and usually manipulated
arithmetically
• 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.
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.
• 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
• 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
• 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
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=
• When the top hex digit is too small, we do the same as in decimal arithmetic. For example, for the final column we have:
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
• 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
• 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!
BCD 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001
BCD 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001
• 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 > 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
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