Course Title: Digital Logic & Circuits Simulation
Lecture Notes: Week-2(L06-L10)
Basics of Digital Electronics: Representation of
Binary Numbers & Binary Codes
Dr. Awadhesh Kumar
Assistant Professor
Department of Computer Science
MMV, BHU
Binary Number Representation: Signed and
Unsigned
• Our day to day life positive numbers are represented without using
(+)sign before the number but negative numbers are represented by
using (-) sign before number.
• Unsigned Representation(unambiguous 0):
• Used to represents only positive numbers.
• Range: 0 to +2n – 1, where n is the number of bits used to represent a number.
• All the numbers are represented uniquely, hence it is unambiguous representation of numbers.
• Example: Represent (10)10 and (253)10 in 8-bit format by using unsigned representation.
• Representation of (10)10 in 8-bit fixed format = (00001010)2
• Representation of (253)10 in 8-bit fixed format = (11111101)2
• Signed Representation:
• Used to represent both positive and Negative Numbers.
• Three ways of Representing a signed Numbers
• Sign Magnitude Representation
• 1’s complement Representation
• 2’s Complement Representation
• Sign Magnitude Representation
• Most Significant Bit (MSB) is used to represent sign of the number and rest of the bits are used
to represent the number.
• If MSB= 0 then the number is positive, and if MSB=1then the number is negative.
• Range : -(2n-1 ) to +2n-1 – 1, where n is the number of fixed bits used to represent a number.
• It is the ambiguous representation because -0 & +0 representation are different.
• Representation of (+0)10 in 8-bit fixed format = (00000000)2
• Representation of (-0)10 in 8-bit fixed format = (10000000)2
• Representation of (+127)10 in 8-bit fixed format = (01111111)2
• Representation of (-127)10 in 8-bit fixed format = (11111111)2
• 1’s complement Representation:
• For representing positive number, the number is converted into binary equivalent in fixed
bit format and for representing negative number, take 1’s complement of positive binary
representation in fixed bits format of that number.
• It is the ambiguous representation because -0 & +0 representation are different.
• Representation of (+0)10 in 8-bit fixed format = (00000000)2
• Representation of (-0)10 in 8-bit fixed format = (11111111)2
• Representation of (+127)10 in 8-bit fixed format = (01111111)2
• Representation of (-127)10 in 8-bit fixed format = (10000000)2 i.e. first represent 127 in 8-
bit fixed binary format and then take its 1’s complement.
• Range: -(2n-1 ) to +2n-1 – 1, where n is the number of fixed bits used to represent a number.
• 2’s Complement Representation:
• For representing positive number, the number is converted into binary equivalent in fixed
bit format and for representing negative number, take 2’s complement of positive binary
representation in fixed bits format of that number.
• It is the unambiguous representation because -0 & +0 representation are same i.e. only
one representation of 0.
• Representation of (+0)10 in 8-bit fixed format = (00000000)2
• Representation of (-0)10 in 8-bit fixed format = (00000000)2
• Representation of (+127)10 in 8-bit fixed format = (01111111)2
• Representation of (-127)10 in 8-bit fixed format = (10000001)2 i.e. first represent 127 in 8-
bit fixed binary format and then take its 2’s complement.
• Range: -(2n-1 -1) to +(2n-1 – 1), where n is the number of fixed bits used to represent a
number.
Subtraction and Addition using Complements
Cases:
1: When Subtrahend is smaller than
Using 10’s Complement minuend
2: When Subtrahend is larger than
Using 9’s Complement minuend
3: When both subtrahend and minuend
are negative number
Using 2’s Complement 3.1: if sign bit of resultant is same as
the sign bit of minuend and
subtrahend and also has a extra carry
Using 1’s Complement bit.
3.2: if sign bit of resultant is
Using r’s Complement different from sign bit of minuend
and subtrahend and also has a extra
Using (r-1)’s Complement carry bit (overflow).
Subtraction and Addition using 10’s & 9’s Complement
• Example1: Perform the arithmetic (63)10 – (55)10 using 10’s complement
• 63-55 = 63+(-55) = 63 + 10’s complement of 55 = 63 +45 =108
• Since there is an extra carry digit means result is positive, ignore the carry digit and rest of the digits are considered as
final result.
• Final Result =08
• Example2: Perform the arithmetic (55)10 – (63)10 using 10’s complement
• 55-63 = 55+(-63) = 55 + 10’s complement of 63 = 55+37 =92
• Since there is no extra carry digit means result is Negative.
• Hence final Result = -(10’s complement of obtained result 92) = - 08
• Example3: Perform the arithmetic (63)10 – (55)10 using 9’s complement
• 63-55 = 63+(-55) = 63 + 9’s complement of 55 = 63 +44 =107
• Since there is an extra carry digit means result is positive, add the extra carry digit with rest of the result to obtain final
result.
• Final Result =(07+1) =08
• Example4: Perform the arithmetic (55)10 – (63)10 using 9’s complement
• 55-63 = 55+(-63) = 55 + 9’s complement of 63 = 55+36 =91
• Since there is no extra carry digit in the above obtained result means result is Negative.
• Hence final Result = -(9’s complement of obtained result 91) = - 08
Subtraction and Addition using 2’s & 1’s Complement
• Example1: Perform the arithmetic (63)10 – (55)10 using 2’s complement in 8-bit fixed binary notation.
• 63-55 = 63+(-55) = Binary equivalent of 63 in 8 bits format + 2’s complement of (Binary equivalent of 55 in 8 bits format)
• = 00111111 + 2’s complement of (00110111) = 00111111+ 11001001 = 100001000
• Obtained results contains total nine bits including one extra carry bit.
• Since there is an extra carry bit means result is positive, ignore the carry bit and rest of the bits are considered as final result.
• Final Result =(00001000)2
• Example2: Perform the arithmetic (55)10 – (63)10 using 2’s complement
• 55-63 = 55+(-63) = Binary equivalent of 55 in 8 bits format + 2’s complement of (Binary equivalent of 63 in 8 bits format)
• = 00110111 + 2’s complement of (00111111) = 00110111 + 11000001 = 11111000
• Obtained results contains total eight bits which means not contain any extra carry bit.
• Since there is no extra carry bit in the obtained result means result is Negative.
• Hence final Result = -(2’s complement of obtained result 11111000) = - (00001000)2
• Example3: Perform the arithmetic (63)10 – (55)10 using 1’s complement in 8-bits fixed binary notation.
• 63-55 = 63+(-55) = Binary equivalent of 63 in 8 bits format + 1’s complement of (Binary equivalent of 55 in 8-bits format)
• = 00111111 + 1’s complement of (00110111) = 00111111+ 11001000 = 100000111
• Obtained results contains total nine bits including one extra carry bit.
• Since there is an extra carry bit means result is positive, add an extra carry bit with rest of the result to obtain a final result.
• Final result = (00000111 +1) =(00001000)2
• Example4: Perform the arithmetic (55)10 – (63)10 using 1’s complement
• 55-63 = 55+(-63) = Binary equivalent of 55 in 8 bits format + 1’s complement of (Binary equivalent of 63 in 8 bits format)
• = 00110111 + 1’s complement of (00111111) = 00110111 + 11000000 = 11110111
• Obtained results contains total eight bits which means not contain any extra carry bit.
• Since there is no extra carry bit in the obtained result means result is Negative.
• Hence final Result = -(1’s complement of obtained result 11110111) = - (00001000)2
• Example5: Perform the arithmetic -(55)10 – (55)10 using 2’s complement in 8-bit fixed binary notation.
• -55-55 = (-55)+(-55) = 2’s complement of (Binary equivalent of 55 in 8 bits format) + 2’s complement of (Binary equivalent of 55 in 8 bits
format)
• = 2’s complement of (00110111) + 2’s complement of (00110111) = 11001001+ 11001001 = 110010010
• Obtained results contains total nine bits including one extra carry bit.
• Since both number are negative (means MSB bit in both of the numbers is 1) and in obtained result, there is an extra carry bit, ignore this extra
carry bit and when we see the result in 8-bits format, the MSB bit is also 1(means sign of the result is same as the sign of the both minuend and
subtrahend bit).
• Final result = -(2’s complement of obtained result in 8 bit format) = - ( 2’s complement of (10010010))
• = -(01101110)2 = - (110 )10
• Example6: Perform the arithmetic -(55)10 – (55)10 using 1’s complement in 8-bit fixed binary notation.
• -55-55 = (-55)+(-55) = 1’s complement of (Binary equivalent of 55 in 8 bits format) + 1’s complement of (Binary equivalent of 55 in 8 bits
format)
• = 1’s complement of (00110111) + 1’s complement of (00110111) = 11001000+ 11001000 = 110010000
• Obtained results contains total nine bits including one extra carry bit.
• Since both number are negative (means MSB bit in both of the numbers is 1) and in obtained result, there is an extra carry bit, Add this extra
carry bit with rest of the obtained result in 8 bit format, and we see that the MSB bit is also 1(means sign of the result is same as the sign of the
both minuend and subtrahend bit).
• Final result = -(1’s complement of (obtained result in 8 bit format after adding extra carry bit)) = - ( 1’s complement of (10010001))
• = -(01101110)2 = - (110 )10
• Example7: Perform the arithmetic –(125)10 – (55)10 using 2’s complement in 8-bit fixed binary
notation.
• -125-55 = (-125)+(-55) = 2’s complement of (Binary equivalent of 125 in 8-bits fixed format) + 2’s
complement of (Binary equivalent of 55 in 8-bits fixed formats)
• = 2’s complement of (01111101) + 2’s complement of (00110111) = 10000011+ 11001001 = 101001100
• Obtained results contains total nine bits including one extra carry bit.
• Since both number are negative (means MSB bit in both of the numbers is 1) and in obtained result,
there is an extra carry bit, ignore this extra carry bit and when we see the result in 8-bits format, the MSB
bit is 0(means sign of the result is different as the sign of the both minuend and subtrahend bit).
• Final result = overflow condition( i.e. we can not represent the result in 8-bit format)
Binary codes
• Used to encode numbers, special Symbols, letters, words, punctuation
marks, emojis, etc.
• Suitable for Digital communication, Computer application, analysis &
Design of Digital circuits etc.
• Weighted Codes
• Non-Weighted Codes
• Binary Coded Decimal Code
• Alphanumeric Codes
• Error Detecting Codes
• Error Correcting Codes
Weighted Binary codes
• It follow positional weight principle.
• Generally used to represents decimal digits 0-9 and numbers.
• Some special weighted binary codes are used to represent each
decimal digit by group of 4-binary bits.
• BCD Code[8 4 2 1] :
• [2 4 2 1] code
• [8 4 -2 -1] code
•
Weighted Binary Code: BCD Code
• Also known as Binary Coded Decimal code.
• It follow the positional weight principal.
• Used to represent only decimal digits (0-9).
• Each decimal digit is represented by group of 4-binary bits.
• The weight of the bits are as follows
Weighted Binary Code: 2421Code
• It follow the positional weight principal.
• Used to represent only decimal digits (0-9).
• Sum of the weights of all the bits (2+4+2+1) is equal to 9;
• Each decimal digit is represented by group of 4-binary bits.
• It is a self complementary code.
• The weight of the bits are as follows:
Weighted Binary Code: 84-2-1 Code
• It follow the positional weight principal.
• Used to represent only decimal digits (0-9).
• Sum of the weights of all the bits is equal = (8+4+(-2) +(-1) = 9;
• Each decimal digit is represented by group of 4-binary bits.
• It is a self complementary code.
• The weight of the bits are as follows:
Decimal Digit BCD (8,4,2,1)Representation 2,4,2,1 Code 8,4,-2,-1 Code
Representation Representation
0 0000 0000 0000
1 0001 0001 0111
2 0010 0010, or 1000 0110
3 0011 0011, or 1001 0101
4 0100 0100, or 1010 0100
5 0101 0101, or 1011 1011
6 0110 0110, or 1100 1010
7 0111 0111, or 1101 1001
8 1000 1110 1000
9 1001 1111 1111
Non-Weighted Binary Codes : Gray Code
• Not follow the positional weight principles.
• Used in the general sequence of hardware-generated binary numbers.
• Used during K-map Simplification
• Only one bit is changed during transition of two successive numbers, hence
also called reflected code.
• Binary to Gray code conversion:
• Most Significant Bit(MSB) of Gray code is same as MSB of Binary code.
• Other bits of the output gray code can be obtained by XORing binary code bit at that
index and its previous index.
• Gray code to Binary code conversion:
• Most Significant Bit(MSB) of Binary code is same as MSB of Gray code.
• Other bits of the output Binary code can be obtained by XORing Gray code bit at that
index and binary code bit at just previous index.
Non-Weighted Binary Codes : Excess-3 code
• Not follow the positional weight principles.
• Non-weighted and self complementary code used to represent decimal
Numbers.
• Add 0011 in each 4-bit BCD code of the decimal number for getting excess-3
code
• Used in biased representation.
• Important role in binary arithmetic's because there is deficiency in addition of
two BCD numbers when their sum exceeds 9.
Self Complementary binary code
• A self-complementary binary code is a code which is always complimented
in itself.
• The sum of the 1's complement and the binary number of a decimal is equal
to the binary number of decimal 9.
• If we perform the 1's complement of excess-3 of a decimal number, it will
be equal to the excess-3 code of the 9's complement of that decimal number.
• 2421, 84-2-1, and Excess-3 codes are the example of self complementary
code.
Weighted and non-weighted binary codes
Alphanumeric code: ASCII & EBCDIC
• American standard code for information interchange
• Any digital computer requires handling of data not use only numbers but
also letters & special symbols.
• If total symbols to encode are between 36 to 64 then 6 binary bits are
required.
• If total symbols to encode are between 64 to 128 then 7 binary bits are
required.
• ASCII code is a standard code to represent 94 printed graphic symbols and
34 non printing characters that are used for various control functions.
• It is a 7-bits standard code to represents 128 characters.
ASCII CODE …..
ASCII CODE …..
EBCDIC Code
• Extended Binary coded Decimal Interchange Code
• It is an 8-bit code used to encode digits, letters, special characters,
symbols etc.
• It encode 256 characters.
Unicode
• International character-encoding system designed to support the electronic
interchange, processing, and display of the written texts of the diverse
languages of the modern and classical world.
• The Unicode Standard using a uniform encoding scheme which includes
letters, digits, punctuation marks, and technical symbols for all the world’s
principal written languages, as well as emoji and other symbols.
• The standard is maintained by the Unicode Consortium.
• By default uses a 16 bit format to encode characters.
• The most recent version contains more than 100,000 characters uses UTF -8
(4 byte long)
Error Detection and Correction codes
Sender(message) Receiver
Communication channel
• Error detection codes are used to detect the error in the received message or bitstream.
• In Error detection and correction codes, if error is detected at receiver end then receiver also able to
correct error.
• Error Detection code:
• If error is detected at receiver end then receiver request for Retransmission of message:
• Parity bit, Checksum, Cyclic Redundancy Check Code (CRC code) are the examples of Error
detection codes.
• Error detection & Correction code[Receiver correct it]: Hamming Code [block code]
Error Detection code: Parity code
Sender(P+ Message) Receiver
Communication channel
• Parity bit P is appended at either the beginning of the message or at end of the
message based on the numbers of 1’s in the message.
• Even Parity
• Odd Parity
• Used to detect error only when single bit is changed in the received message.
• Message: 100110
• Sender send a message including even parity bit:1100110
• Sender send a message including odd parity bit: 0100110
• Receiver Receive the message including even parity bit: 1100100 → Error
• Receiver Receive the message including odd parity bit: 0100110→ Error Free
References
• Digital Design, Textbook by M. Morris Mano and Michael D. Ciletti
• Digital Logic And Computer Design By M. Morris Mano