Digital Logic Design
EEE211
Lecture 2
Dr Atiqur Rahman
Dept. of Electrical and Computer Engineering
North South University
Binary Arithmetic
Complements
Signed Binary numbers
Binary addition, subtraction and Multiplication
Complements
Used to simplify the subtraction operation and logical manipulations
Simplifying operations lead to simpler, less expensive circuits
Two types of Complements:
Radix Complement : ( r’s complement)
Diminished radix complement : (r-1)’s complement
Diminished Radix Complement:
Given a number N having n digits in Base -r
the (r-1)’s complement of N is: (rn – 1) - N
Example:
9’s complement of 246700 is 999999 – 246700 = 753299
1’s complement of 1101100 is 1111111 – 1101100 = 0010011
Radix Complement:
Given a number N having n digits in Base -r
the r’s complement of N is: rn – N for N 0
= (rn –1) – N +1
= (r-1)’s complement + 1
Example:
10’s complement of 246700 is = 9’s complement of 246700 + 1
= ( 999999 – 246700 ) + 1
= 753299 + 1
= 753300
2’s complement of 1101100 is = 1’s complement of 1011000 + 1
= (1111111 – 1101100 ) +1
= 0010011 + 1
= 0010100
Signed and Unsigned Number
Binary numbers with only two symbols, 0 and 1.
No minus sign (-) to represent negative numbers in Binary
Both signed and unsigned number consist of a string of bits when
represented in a computer
User determine whether the number is signed or unsigned
Unsigned number: The leftmost bit is the most significant bit
of the number
Signed number: The leftmost bit is the sign bit and rest
represents the number
Sign Bit: bit placed in the leftmost position of the number.
Conventionally
0 : indicate the positive number
1: indicate the negative number
Signed Binary Integers
Three ways to represent negative binary numbers.
Signed-magnitude representation:
The number consists of magnitude and sign bit
8-bit binary signed magnitude representation of +(9)10 is
(00001001 )2 and (-9)10 is (10001001 )2
Signed 1’s complement representation:
Taking 1’s complement of the positive number including the sign bit
8-bit binary signed 1’s complement representation of -(9)10 is
(11110110)2
Signed 2's complement representation:
Taking 2’s complement of the positive number including the sign bit
8-bit binary signed 2’s complement representation of -(9)10 is
(11110111)2
The Binary Number Addition
To add two 1-bit (representations of) integers: Count the number of
ones in a column and write the result in binary.
The right bit of the result is placed under the column of bits. The left
bit is called the "carry out of the column".
1 1 1 1 0 0 0 0
0 0 1 1 1 0 1 0 1 0 1 0
0 1 0 1 1 1 0 0 1 1 0 0
--- --- --- --- --- --- --- --- --- --- --- ---
0 01 01 10 11 10 10 01 10 01 01 00
+6 00000110
+13 00001101
--------- ------------------
+19 00010011
Binary Number Subtraction
Similar to decimal system using borrowing:
Subtract one binary number from another by using the
standard techniques adapted for decimal numbers
(subtraction of each bit pair, right to left, "borrowing"
as needed from bits to the left).
Subtraction by adding with two’s complement:
Represent negative binary numbers by using the
"two's complement" method and a negative place-
weight bit. Here, we'll use those negative binary
numbers to subtract through addition.
Subtraction: 710 - 510
Addition equivalent: 710 + (-510)
Represent (+7)10 and (-5)10 in binary 2's complement form
So, in 8-bit binary representation,
+(7)10 = (00000111)2 and (-5)10 = (11111011)2
Now, let's add them together:
Since we've already defined our
number bit field as three bits
11111111 <--- Carry bits plus the negative-weight bit,
00000111 the fifth bit in the answer (1)
+ 11111011 will be discarded to give us a
------------- result of 00102, or positive two,
100000010 which is the correct answer.
|
Discard extra bit
.
. Answer = (00000010)2
Binary Codes
An n-bit binary code is a group of n bits that assumes up to
2n distinct combinations of 1’s and 0’s with each combination
representing one element of set that is being coded
The bit combination of an n-bit code is determined from the
count in binary 0 to 2n -1
Example:
A set of 8 elements can be coded with 3-bit binary codes
(as 8 = 23) with each element assigned one of the following bit
combinations:
000, 001, 010, 011, 100, 101, 110, 111
Nibble: In computers and digital technology, a nibble
is four binary digits or half of an eight-bit byte.
Maximum number in a nibble :
(1111)bin = (15)dec = (F) hex
A nibble can be conveniently represented by one
hexadecimal digit.
Byte: A byte is eight binary digits (or bits)
One byte = 8 bits = 2 nibbles
Maximum number in a byte :
(11111111)bin = (255)dec = (FF) hex
BCD: Binary-coded decimal
A method of using binary digits to represent the decimal
digits 0 through 9. A decimal digit is represented by four
binary digits, as shown below:
The binary combinations
1010 to 1111 are invalid and
are not used in BCD
BCD Conversion
BCD and binary are not the same.
For example, 4910 in binary is 1100012,
but 4910 in BCD is 01001001BCD
4 9
0100 1001 = 01001001BCD
Each decimal digit is converted to its binary equivalent.
Similarly,
(185)10 = ( 0001 1000 0101)BCD = (10111001)2
(212)10 = ( ? )BCD = (?)2
BCD Addition
Example 1:
4 0100 Represent in BCD
+5 +0101 Represent in BCD
9 1001 BCD SUM
(9)10 = (1001)BCD = (1001)2
Example 2:
1 carry 1 carry
184 0001 1000 0100 in BCD
+ 576 +0101 0111 0110 in BCD
0111 10000 1010 Binary sum for each BCD
+0110 +0110 Add 6 if sum is above 1001
760 0111 0110 0000 BCD SUM
(760)10 = (0111 0110 0000)BCD = (1011111000)2
Gray Code: A Gray code is an encoding of numbers so that
adjacent numbers have a single digit differing by 1
Also known as Reflected Binary Code
Decimal Number Gray Code
0 0000
1 0001
2 0011
3 0010
4 0110
5 0111
6 0101
7 0100
8 1100
9 1101
10 1111
11 1110
12 1010
13 1011
14 1001
15 1000
ASCII Code
ASCII, pronounced "ask-key", is the common code for
microcomputer equipment. The standard ASCII
character set consists of 128 decimal numbers ranging
from zero through 127 assigned to letters, numbers,
punctuation marks, and the most common special
characters.
The Extended ASCII Character Set also consists of
128 decimal numbers and ranges from 128 through 255
representing additional special, mathematical, graphic,
and foreign characters.
The Standard ASCII character set is divided into four
groups of 32 characters.
The first 32 characters, form a special set of non-
printing characters called the control characters. We call
them control characters because they perform various
printer/display control operations rather than displaying
symbols.
Examples of common control characters include:
•carriage return which positions the cursor to
the left side of the current line of characters,
•line feed which moves the cursor down one
line on the output device
•back space which moves the cursor back one
position to the left
Unfortunately, different control characters perform different
operations on different output devices. There is very little
standardization among output devices. To find out exactly
how a control character affects a particular device, you will
need to consult its manual.
The second group of 32 ASCII character codes
comprise various punctuation symbols, special
characters, and the numeric digits. The most notable
characters in this group include the:
•space character
•numeric digits 0 through 9
Note that the numeric digits differ from their numeric
values only in the high order nibble. By subtracting
30h from the ASCII code for any particular digit you
can obtain the numeric equivalent of that digit.
The third group of 32 ASCII characters is
reserved for the upper case alphabetic characters.
The ASCII codes for the characters "A" through "Z"
lie in the range 41h through 5Ah. Since there are
only 26 different alphabetic characters, the
remaining six codes hold various special symbols.
The fourth, and final, group of 32 ASCII
character codes are reserved for the lower case
alphabetic symbols, five additional special symbols,
and another control character (delete).
ASCII Character Codes
21
Error Detecting Code - Parity Coding
Parity bit: A parity bit is an extra bit included with a
message to make the total number of 1’s either even or odd
Original message bits With even parity with odd parity
1000001 01000001 11000001
1010100 11010100 01010100
Parity bit helps to detect error during the transmission of information