Title: Tutorial: ITI1100
1Tutorial ITI1100
- Dewan Tanvir Ahmed
- SITE, UofO
- Email dahmed_at_site.uottawa.ca
2Binary Numbers
- Base (or radix)
- 2
- example 0110
- Number base conversion
- example 41 101001
- Complements
- 1's complements ( 2n- 1 ) - N
- 2's complements 2n - N
- Subtraction addition with the 2's complement
- Signed binary numbers
- signed-magnitude, 10001001
- signed 1's complement, 11110110
- signed 2's complement. 11110111
3Binary Number System
Base 22 Digits 0, 1 Examples 1001b 1 23
0 22 0 21 1 20 8
1 9 1010 1101b 1 27 1
25 1 23 1 22 1
128 32 8 4 1
173 Note it is common to put
binary digits in groups of 4 to make it easier to
read them.
4Ranges for Data Formats
5In General (binary)
6Signed Integers
- unsigned integers positive values only
- Must also have a mechanism to represent signed
integers (positive and negative values!) - -1010 ?2
- Two common schemes
- sign-magnitude and
- twos complement
7Sign-Magnitude
- Extra bit on left to represent sign
- 0 positive value
- 1 negative value
- 6-bit sign-magnitude representation of 5 and 5
8Ranges (revisited)
9In General
10Difficulties with Sign-Magnitude
- Two representations of zero
- Using 6-bit sign-magnitude
- 0 000000
- 0 100000
- Arithmetic is awkward!
11Complementary Representations
- 1s complement
- 2s complement
- 9s complement
- 10s complement
12Complementary Notations
- What is the 3-digit 10s complement of 207?
- Answer
- What is the 4-digit 10s complement of 15?
- Answer
- 111 is a 10s complement representation of what
decimal value? - Answer
13Exercises Complementary Notations
- What is the 3-digit 10s complement of 207?
- Answer 793
- What is the 4-digit 10s complement of 15?
- Answer 9985
- 111 is a 10s complement representation of what
decimal value? - Answer 889
142s Complement
- Most common scheme of representing negative
numbers - natural arithmetic - no special rules!
- Rule to represent a negative number in 2s C
- Decide upon the number of bits (n)
- Find the binary representation of the ve value
in n-bits - Flip all the bits
- Add 1
152s Complement Example
- Represent -5 in binary using 2s complement
notation - Decide on the number of bits
- Find the binary representation of the ve value
in 6 bits - Flip all the bits
- Add 1
6 (for example)
111010
16Sign Bit
- In 2s complement notation, the MSB is the sign
bit (as with sign-magnitude notation) - 0 positive value
- 1 negative value
2s complement
17Complementary Notation
- Conversions between positive and negative numbers
are easy - For binary (base 2)
18Example
2s C
ve
-ve
2s C
19Range for 2s Complement
- For example, 6-bit 2s complement notation
000000
111111
000001
011111
100000
100001
-32 -31 ... -1 0 1 ... 31
20Ranges
21In General (revisited)
22What is -6 plus 6?
232s Complement Subtraction
- Easy, no special rules
- Subtract??
- Actually addition!
A B A (-B)
add
2s complement of B
24What is 10 subtract 3?
- 7, but
- Lets do it (well use 6-bit values)
10 3 10 (-3) 7
001010111101 000111
3 000011 -3 111101
25What is 10 subtract -3?
- 13, but
- Lets do it (well use 6-bit values)
10 (-3) 10 (-(-3)) 13
-3 111101 3 000011
26M - N
- M 2s complement of N
- M (2n - N) M - N 2n
- If M ? N
- Produce an carry, which is discarded
- If M lt N
- results in 2n - (N - M), which is the 2s
complement of (N-M)
27Overflow
- Carry out of the leading digit
- If we add two positive numbers and we get a carry
into the sign bit we have a problem - If we add two negative numbers and we get a carry
into the sign bit we have a problem - If we add a positive and a negative number we
won't have a problem - Assume 4 bit numbers (7 -8)
28N 4
Number Represented
Unsigned 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Binary 0000 0001 0010 0011 0100 0101 0110 0111 1
000 1001 1010 1011 1100 1101 1110 1111
Signed Mag 0 1 2 3 4 5 6 7 -0 -1 -2 -3 -4 -5 -6 -
7
1's Comp 0 1 2 3 4 5 6 7 -7 -6 -5 -4 -3 -2 -1 -0
2's Comp 0 1 2 3 4 5 6 7 -8 -7 -6 -5 -4 -3 -2 -1
29Overflow
- If we add two positive numbers and we get a carry
into the sign bit we have a problem -
- 3 0011 4 0100
- 3 0011 4 0100
- 6 0110 8 1000
30Overflow
- -5 1011 -4 1100
- -3 1101 -5 1011
- -8 11000 -9 10111
- If we add two negative numbers and we get a carry
into the sign bit we have a problem
31Overflow
- If we add a positive and a negative number we
won't have a problem - 5 0101 -4 1100
- -3 1101 5 0101
- 2 10010 1 10001
32Overflow
- If we add two positive numbers and we get a carry
into the sign bit we have a problem - 3 0011 4 0100
- 3 0011 4 0100
- 6 0110 8 1000
carry in 0 carry out 0
carry in 1 carry out 0
33Overflow
- If we add two negative numbers and we get a carry
into the sign bit we have a problem - -5 1011 -4 1100
- -3 1101 -5 1011
- -8 11000 -9 10111
carry in 1 carry out 1
carry in 0 carry out 1
34Overflow
- If we add a positive and a negative number we
won't have a problem - 5 0101 -4 1100
- -3 1101 5 0101
- 2 10010 1 10001
carry in 1 carry out 1
carry in 1 carry out 1
35Binary Codes
- n-bit binary code
- 2n distinct combinations
- BCD Binary Coded Decimal (4-bits)
- 0 0000
- 1 0001
-
- 9 1001
- BCD addition
- Get the binary sum
- If the sum gt 9, add 6 to the sum
- Obtain the correct BCD digit sum and a carry
36Binary Codes
- ASCII code
- American Standard Code for Information
Interchange - alphanumeric characters, printable characters
(symbol), control characters - Error-detection code
- one parity bit - an even numbered error is
undetected - A 411000001 - - gt
- 01000001 (even),
- 11000001 (odd)
37Binary Logic
- Boolean algebra
- Binary variables X, Y
- two discrete values (true or false)
- Logical operations
- AND, OR, NOT
- Truth tables
38Logic Gates
- Logic circuits
- circuits logical manipulation paths
- Computations and controls
- combinations of logic circuits
- Logic Gates
39Timing diagram
40Thank You!