LSD Module 1
LSD Module 1
MODULE 1
Number Systems Operations and Codes
1
LOGIC DESIGN
• Digital logic design is basis of electronic systems, such as
computers and cell phones
• Digital Logic is rooted in binary code, a series of zeroes and ones
• Digital Logic Design is foundational to fields of electrical
engineering and computer engineering
• Digital Logic designers build complex electronic components that
use both electrical and computational characteristics
• Digital Logic Design is used to develop hardware, such as circuit
boards and microchip processors
2
SWITCHING THEORY
• Switching Theory is about using switches to implement Boolean
expressions and logic gates for logic design of digital circuits
• Digital logic gates whose inputs and output can switch between
two distinct logical values of 0 and 1
3
DIGITAL NUMBER SYSTEMS
Number Systems
Decimal
Binary
Octal
Hexadecimal
4
DECIMAL NUMBER SYSTEMS
5
• Position of each digit in a weighted number system is assigned
a weight based on base or radix of system
• Radix of decimal numbers is ten
• Ten symbols (0 through 9) are used to represent any number
• For fractional decimal numbers, column weights are negative
powers of ten that decrease from left to right:
…105 104 103 102 101 100.
• Column weights of decimal numbers are powers of ten that
increase from right to left beginning with 100 =1:
102 101 100. 10-1 10-2 10-3 10-4 … Number Systems and
Codes by Azian
6
• Decimal numbers can be expressed as sum of products of
each digit times column value for that digit
• Number 9240 can be expressed as
(9 x 103) + (2 x 102) + (4 x 101) + (0 x 100)
or
9 x 1,000 + 2 x 100 + 4 x 10 + 0 x 1
7
BINARY NUMBER SYSTEMS
8
• For digital systems, binary number system is used
• Binary has a radix of two and uses digits 0 and 1
• Column weights of binary numbers are powers of two that
increase from right to left beginning with 20 =1:
…25 24 23 22 21 20.
• For fractional binary numbers, column weights are negative
powers of two that decrease from left to right:
22 21 20. 2-1 2-2 2-3 2-4 …
Number Systems and
Codes by Azian
9
OCTAL NUMBER SYSTEMS
(CONT…)
10
Decimal Octal Binary
Group the binary number by 3-bits starting from the right. Thus,
1130168
Number Systems and
Codes by Azian
12
HEXADECIMAL NUMBER SYSTEMS
13
Decimal Hexadecimal Binary
• Hexadecimal is a weighted number 0 0 0000
system 1 1 0001
2 2 0010
• Column weights are powers of 16, which 3 3 0011
increase from right to left 4 4 0100
5 5 0101
6 6 0110
Column weights {4096
3 2 1
16 16 16 16 .
256 16 1 .
0
7 7 0111
8 8 1000
Express 1A2F16 in decimal. 9 9 1001
10 A 1010
Start by writing the column weights: 11 B 1011
4096 256 16 1 12 C 1100
1 A 2 F16 13 D 1101
1(4096) + 10(256) +2(16) +15(1) = 670310 14 E 1110
Number Systems and
15 F Codes by Azian
1111
14
• Hexadecimal uses sixteen characters to represent numbers
15
CONVERSION BETWEEN NUMBER
SYSTEMS
Decimal Binary Octal Hexadecimal
Conversion Conversion Conversion Conversion
Binary Decimal
Decimal Decimal
Octal Octal
Binary Binary
Hexadecimal Hexadecimal
16
DECIMAL TO BINARY
LSB
50 2 0
25 2 1 MSB – Most Significant Digit
12 2 0
LSB – Least Significant Digit
6 2 0
3 2 1
1 1
MSB
=1 1 0 0 1 02
Number Systems and
Codes by Azian
17
DECIMAL TO OCTAL
LSB
50 8 2
MSB – Most Significant Digit
6 6
LSB – Least Significant Digit
MSB
= 6 2 8
18
DECIMAL TO HEXADECIMAL
LSB
MSB
= 3 2 16
19
DECIMAL (FRACTION) TO BINARY
CONVERSION
Multiply the number by the ‘Base’(=2)
Take the integer (either 0 or 1) as a coefficient
Take the resultant fraction and repeat the division
Example: (0.625)10
Integer Frac tion Coefficient
0.625 * 2 = 1 . 25 a-1 = 1
0.25 * 2 = 0 . 5 a-2 = 0
0.5 *2= 1 . 0 a-3 = 1
Answer: (0.625)10 = (0.a-1 a-2 a-3)2 = (0.101)2
20
Decimal (Fraction) to Binary
Conversion
21
DECIMAL (FRACTION) TO OCTAL
CONVERSION
Example: (0.3125)10
Integer Fraction Coefficient
0.3125 * 8 = 2 . 5 a-1 = 2
0.5 *8= 4 . 0 a-2 = 4
Answer: (0.3125)10 = (0.a-1 a-2 a-3)8 = (0.24)8
22
BINARY TO DECIMAL
(11101) 2
= (1x24) + (1x23) + (1x22) + (0x21 ) + (1x20)
= 16 + 8 + 4 + 1
= (29)10
Number Systems and
Codes by Azian
23
BINARY TO OCTAL
3 7 2 = 3728
24
BINARY TO OCTAL Octal Binary
0 000
1 001
2 010
Assume Zeros
Example: 3 011
( 1 0 1 1 0 . 0 1 )2 4 100
5 101
6 110
( 2 6 . 2 )8 7 111
25
BINARY TO HEXADECIMAL
2 A F = 2AF16
26
BINARY TO HEXADECIMAL
Hex Binary
0 0000
1 0001
2 0010
3 0011
4 0100
5 0101
Assume Zeros 6 0110
Example: 7 0111
8 1000
( 1 0 1 1 0 . 0 1 )2 9 1001
A 1010
B 1011
C 1100
D 1101
(1 6 . 4 )16 E 1110
F 1111
Works both ways (Binary to Hex & Hex to Binary) Number Systems and
Codes by Azian
27
OCTAL TO DECIMAL
(362) 8
= (3x82) + (6x81) + (2x80)
= 192 + 48 + 2
= (242)10
Number Systems and
Codes by Azian
28
OCTAL TO BINARY
= 011111010
29
HEXADECIMAL TO DECIMAL
(19B) 16
= (1x162) + (9x161) + (11x160)
= 256 + 144 + 11
= (411)10
Number Systems and
Codes by Azian
30
HEXADECIMAL TO BINARY
2AF16 = 2 A F
31
OCTAL TO HEXADECIMAL
Convert to Binary as an intermediate step
Example:
( 2 6 . 2 )8
( 0 1 0 1 1 0 . 0 1 0 )2
(1 6 . 4 )16
Number Systems and
Works both ways (Octal to Hex & Hex to Octal) Codes by Azian
32
BINARY ADDITION
33
BINARY ADDITION
34
BINARY ADDITION
1 1 1 1 1 1
1 1 1 1 0 1 = 61
+ 1 0 1 1 1 = 23
1 0 1 0 1 0 0 = 84
36
BINARY SUBTRACTON
1 2 = (10)2
0 2 2 0 0 2
1 0 0 1 1 0 1 = 77
− 1 0 1 1 1 = 23
0 1 1 0 1 1 0 = 54
1 0 1 1 1
x 1 0 1 0
0 0 0 0 0
1 0 1 1 1
0 0 0 0 0
1 0 1 1 1
1 1 1 0 0 1 1 0
Number Systems and
Codes by Azian
BINARY DIVISION
41
2’S COMPLEMENT
• The 2’s complement of a binary number is found by adding
1 to the LSB of 1’s complement
0 0 1 1 0 1 0 1
Input bits
Carry
Adder
in (add 1)
Output bits (sum)
42
SIGNED BINARY NUMBERS
• MSB in a signed number is the sign bit, that tells you if
number is positive or negative
• Computers use a modified 2’s complement for signed numbers
• Positive numbers are stored in true form (with a 0 for sign bit)
and negative numbers are stored in complement form (with a 1
for sign bit)
43
SIGNED BINARY NUMBERS
• Negative numbers are written as the 2’s complement of
corresponding positive number
The negative number -58 is written as:
1’s complement of +58=11000101
2’s complement of +58=11000101+1= 11000110
-58 = 11000110 (complement form)
Sign bit Magnitude bits
An easy way to read a signed number that uses this notation is to
assign the sign bit a column weight of -128 (for an 8-bit number).
Then add the column weights for the 1’s.
Assuming that the sign bit = -128, show that 11000110 = -58
as a 2’s complement signed number:
Column weights: -128 64 32 16 8 4 2 1.
1 1 0 0 0 1 1 0
-128 +64 +4 +2 = -58
Number Systems and
Codes by Azian
44
ARITHMETIC OPERATIONS
WITH SIGNED NUMBERS
45
ARITHMETIC OPERATIONS
WITH SIGNED NUMBERS
• Note that if the number of bits required for the answer is
exceeded, overflow will occur
• This occurs only if both numbers have the same sign. The
overflow will be indicated by an incorrect sign bit.
Two examples are:
10000001 = -127
10000001 = -127
Discard carry 100000010 = +2
46
ARITHMETIC OPERATIONS
WITH SIGNED NUMBERS
• Rules for subtraction: 2’s complement subtrahend and add
numbers
• Discard any final carries, result is in signed form
47
Hexadecimal Addition
• Start with least significant hexadecimal digits
• Let Sum= summation of two hex digits
• If sum is greater than or equal to 16, then
Sum=Sum-16 and carry 1
48
Hexadecimal Subtraction
• Start with least significant hexadecimal digits
• Let Difference=subtraction of two hex digits
• If Difference is negative, then
Difference=16+Difference and borrow=-1
49
Octal Addition
• Start with least significant octal digits
• Let Sum= summation of two octal digits
• If sum is greater than or equal to 8, then
Sum=Sum-8 and carry 1
50
Octal Subtraction
• Start with least significant octal digits
• Let Difference=subtraction of two octal digits
• If Difference is negative, then
Difference=8+Difference and borrow=-1
51
9’s Complement
• 9’s complement of a decimal number is found by subtracting
each digit in number from 9
• 9’s complement of each of decimal digits is as follows
52
10’s Complement
• 10’s complement of a decimal number can be found by
adding 1 to 9’s complement of that decimal number
53
BCD CODE
• Binary coded decimal (BCD) is a weighted code
Coding
decimal to its
binary
equivalent
BCD
CODE
Code available Four bits = one
0000 - 1001 decimal digit
54
BCD code
• commonly known as a weighted 8421 Decimal Binary BCD
0 0000 0000
BCD code, with 8, 4, 2 and 1
1 0001 0001
representing weights of different bits 2 0010 0010
starting from most significant bit (MSB) 3 0011 0011
and proceeding towards least significant 4 0100 0100
bit (LSB 5 0101 0101
6 0110 0110
• It is commonly used in digital systems 7 0111 0111
when it is necessary to show decimal 8 1000 1000
9 1001 1001
numbers such as in clock displays.
10 1010 0001 0000
11 1011 0001 0001
The table illustrates the difference
12 1100 0001 0010
between straight binary and BCD. BCD 13 1101 0001 0011
represents each decimal digit with a 4- 14 1110 0001 0100
Number Systems and
bit code. Notice that the codes 1010 15 1111 0001 0101
Codes by Azian
through 1111 are not used in BCD.
55
BCD code
56
BCD Addition
• Use binary arithmetic to add BCD digit
• If binary sum is less than or equal to 1010 (9 in decimal),
corresponding BCD sum digit is correct
• If binary sum is more than 1010, must add 0110 (6 in decimal) to
corresponding BCD sum digit in order to produce correct carry
into digit to left
57
BCD Addition
• Add 2905+1897 in BCD
58
BCD Subtraction Using 9’s
Complement
• BCD Subtraction using 9s Complement can be used to
perform subtraction by adding minuend to 9s Complement
of subtrahend
• In 9s Complement subtraction when 9s Complement of
smaller number is added to larger number carry is generated,
It is necessary to add this carry to result (this is called an
end-around carry)
• When larger number is subtracted from smaller one, there is
no carry, and result is in 9s Complement form and negative
Number Systems and
Codes by Azian
59
BCD Subtraction
60
BCD Subtraction Using 10’s
Complement
• BCD Subtraction using 10s Complement can be used to
perform subtraction by adding minuend to 10s Complement
of subtrahend and dropping carry
61
Character Coding Schemes
• In computing, a single character such as a letter, a number
or a symbol is represented by a group of bits
• Number of bits per character depends on coding scheme
used
• Most common coding schemes are:
1. Binary Coded Decimal (BCD)
2. Extended Binary Coded Decimal Interchange Code
(EBCDIC)
3. American Standard Code for Information Interchange
(ASCII)
62
ASCII CODE
• ASCII (American Standard Code for Information Interchange)
is a code for alphanumeric characters and control characters
• Every time a character is typed on a keyboard a code number
is transmitted to computer
• Code numbers are stored in binary on computers as Character
Sets called ASCII
• Table below shows a version of ASCII that uses 7 bits to code
each character
• 128 different characters characters i.e. 27 can be represented
using ASCII
63
ASCII CODE
• Biggest number that can be held in 7-bits is 1111111 in
binary (127 in decimal)
• More than enough to cover all of characters on a standard
English-Language keyboard
• First 32 characters are control characters
• In 1981, IBM introduced extended ASCII, which is an 8-bit
code and increased the character set to 256
• Characters from 0 to 31 are control characters, 32 to 64 special
characters, 65 to 96 uppercase letters and few symbols, 97 to
127 lowercase letters and other symbols and 128 to 255 are
other symbols
Number Systems and
Codes by Azian
64
Number Systems and
Codes by Azian
65
Number Systems and
Codes by Azian
66
EXTENDED ASCII TABLE
67
EBCDIC CODE
• It is pronounced as “ebb-see-dick
68
EBCDIC CODE
• In EBCDIC code eight bits for each character is divided into
two four-bit zones
69
EBCDIC CODE TABLE
70
BINARY CODES
• A binary code represents text, computer processor instructions,
or any other data using a two-symbol system
• Two-symbol system used is often "0" and "1" from binary
number system
• For example, a binary string of eight bits can represent any of
256 possible values and can, therefore, represent a wide variety
of different items
• Following are some binary codes
1. Decimal codes
2. Error detection codes
3. Reflected code
71
ERROR DETECTION
CODES
• These are used to detect errors present in received data bitstream
• These codes contain some bits, which are appended to original
bit stream
• These codes detect error, if it is occurred during transmission of
original data bit stream
• Example − Parity code, Checksum, Cyclic Redundancy Check
72
PARITY CODE
• It is easy to append one parity bit either to left of MSB or to right
of LSB of original bit stream
• There are two types of parity codes, namely even parity code and
odd parity code based on type of parity being chosen
• Parity bit helps to check if any error occurred in data during
transmission.
73
EVEN PARITY CODE
• Value of even parity bit should be zero, if even number of ones
present in the binary code. Otherwise, it should be one
• So that, even number of ones present in even parity code
• Even parity code contains data bits and even parity bit
• Following table shows even parity codes corresponding to each
3-bit binary code
• Here, even parity bit is included to right of LSB of binary code
74
EVEN PARITY CODE
75
ODD PARITY CODE
• Value of odd parity bit should be zero, if odd number of ones
present in binary code. Otherwise, it should be one. So that, odd
number of ones present in odd parity code
• Odd parity code contains data bits and odd parity bit
• Following table shows odd parity codes corresponding to each
3-bit binary code
• Here, odd parity bit is included to right of LSB of binary code
76
ODD PARITY CODE
77
PARITY CHECKING STEPS
Error detection using single parity check involves following steps
Step-01:
At sender side,
• Total number of 1’s in data unit to be transmitted is counted.
• Total number of 1’s in the data unit is made even in case of even
parity.
• Total number of 1’s in the data unit is made odd in case of odd
parity.
• This is done by adding an extra bit called as parity bit.
78
PARITY CHECKING STEPS
Step-02:
Step-03:
At receiver side,
• Receiver receives transmitted code word
• Total number of 1’s in the received code word is counted
79
PARITY CHECKING STEPS
Then, following cases are possible
• If total number of 1’s is even and even parity is used, then
receiver assumes that no error occurred.
• If total number of 1’s is even and odd parity is used, then
receiver assumes that error occurred.
• If total number of 1’s is odd and odd parity is used, then receiver
assumes that no error occurred.
• If total number of 1’s is odd and even parity is used, then
receiver assumes that error occurred.
80
PARITY CHECK EXAMPLE
• Consider the data unit to be transmitted is 1001001 and even
parity is used
At Sender Side-
81
PARITY CHECK EXAMPLE
82
PARITY CHECK EXAMPLE
At Receiver Side-
• After receiving the code word, total number of 1’s in the code
word is counted.
• Consider receiver receives the correct code word = 10010011.
• Even parity is used and total number of 1’s is even.
• So, receiver assumes that no error occurred in the data during the
transmission.
83
PARITY CHECK EXAMPLE
Advantage-
• This technique can not detect an even number of bit errors (two,
four, six and so on).
• If even number of bits flip during transmission, then receiver can
not catch the error.
Number Systems and
Codes by Azian
84
PARITY CHECK EXAMPLE
• Consider data unit to be transmitted is 10010001 and even parity
is used.
• Then, code word transmitted to the receiver = 100100011
• Consider during transmission, code word modifies as 101100111.
(2 bits flip)
• On receiving the modified code word, receiver finds the number
of 1’s is even and even parity is used.
• So, receiver assumes that no error occurred in the data during
transmission though the data is corrupted.
85
CHECKSUM
• It also uses same method of parity bits transmitter send data
followed by bits known as checksum bits
Algorithm:-
1. In checksum error detection scheme, data is divided into k
segments each of m bits.
2. In sender end segments are added using complement arithmetic to
get the sum, sum is complemented to get Checksum.
3. Checksum segment is sent along with data segments.
4. At receiver end, all received segments are added using 1s
complement arithmetic to get sum. Sum is complemented
5. If result is zero, received data is accepted; otherwise discarded
86
CHECKSUM
87
CHECKSUM EXAMPLE
88
GRAY CODE/REFLECTED
CODE
• Reflected binary code or Gray code is an ordering of binary
numeral system such that two successive values differ in only one
bit (binary digit)
• Gray code is not weighted that means it does not depends on
positional value of digit
• Gray code also known as reflected binary code, because the first
(n/2) values compare with those of the last (n/2) values, but in
reverse order.
89
GRAY CODE/REFLECTED
CODE
90
GRAY CODE
Remove most significant bit and you
Consider gray code sequence obtain a nice reflected sequence:
x000
0000
x001
0001
x011
0011
x010
0010
x110
0110
x111
0111
x101
0101
x100 ----
0100
---mirror
1100
x100
1101
x101 same kind of reflection can
1111
x111 be found for Gray sequences
1110
x110 of any width
1010
x010
1011
x011
1001 Number Systems and
x001 Codes by Azian
1000
x000 91
GRAY CODE
92
GRAY CODE
Gray Code to Binary Conversion
• MSB of binary number will be equal to the MSB of the given
gray code.
• Second bit of binary code will be exclusive-or (XOR) of first bit
of binary code and second bit of given gray code, i.e if both the
bits are same the result will be 0 and if they are different the
result will be 1.
• Third bit of binary code will be equal to exclusive-or (XOR) of
second bit of binary code and third bit of the given gray code
• Thus binary to gray code conversion goes on
93
GRAY CODE
Binary to
Gray Code
Gray to
Binary
Code
94
END……………….
95