79 - Unit 2.2
79 - Unit 2.2
79 - Unit 2.2
Lecturer
Gunjan Gupta
HSMSS
10110000
+01001111
11111111
Complements
• Radix Complement
The r's complement of an n-digit number N in base r is defined as
rn – N for N ≠ 0 and as 0 for N = 0. Comparing with the (r 1) 's complement, we
note that the r's complement is obtained by adding 1 to the (r 1) 's complement,
since rn – N = [(rn 1) – N] + 1.
• Example: Base-10
The 10's complement of 012398 is 987602
The 10's complement of 246700 is 753300
• Example: Base-2
10110000
01001111
+ 1
01010000
Signed Binary Numbers
How do we represent negative numbers ?
How do we do it in decimal numbers
Negative sign
Can we use negative sign in binary ?
Computer/digital world only understand 0 and 1
How about reserving one bit for sign ?
Sign Magnitude Form
• MSB is designated to show sign.
• The convention is to make the sign bit 0 for positive and 1 for
negative.
• Example ( 4 bit binary number)
1. (7) 10 = (0111) 2
2. (-7) 10 = (1111) 2
• Range for n bit numbers is (-2n-1 –1) 10 to (2n-1 –1) 10
• i.e. range of 4 bit number is (-7) 10 to (7) 10
• Problem: Two zeros (1000)2 and (0000) 2
1’s Complement Form
1’s complement of the given positive number represents it’s
corresponding negative number.
Example ( 4 bit binary number)
(7) 10 = (0111) 2
(-7) 10 = (1000) 2
Range for n bit numbers is (-2n-1 –1) 10 to (2n-1 –1) 10
i.e. range of 4 bit number is (-7) 10 to (7) 10
Problem: Two zeros (1111)2 and (0000) 2
2’s Complement Form
• 2’s complement of the given positive number represents it’s
corresponding negative number.
• Example ( 4 bit binary number)
1. (7) 10 = (0111) 2
2. (-7) 10 = (1001) 2
• Range for n bit numbers is (-2n-1 -1)10 to (2n-1 ) 10
• i.e. range of 4 bit number is (-7) 10 to (8) 10
• Only one zero (0000) 2
Signed Binary Numbers
Binary Subtraction Using 1’s Complement
Step 1: Convert number to be subtracted (subtrahend) to it’s 1’s
complement form
Step 2: Add the result obtained from step 1 to minuend.
Step 3:
Case 1 :
If the final carry is 1, then add the carry to the result obtained in
step 2.
Case 2 :
If the final carry is not generated, result obtained in step 2
is negative and in the 1’s complement form.
Examples:
Using 1’s complement form
1. Perform (1100) 2 - (0101) 2
2. Perform (0101) 2 - (1100) 2
Class Work
Using 1’s complement form
1. Perform (1011) 2 - (0100) 2
2. Perform (11001) 2 - (1111) 2
Binary Subtraction Using 2’s Complement
Step 1: Convert number to be subtracted (subtrahend) to it’s 2’s
complement form
Step 2: Add the result obtained from step 1 to minuend.
Step 3:
Case 1 :
If the final carry is 1, discard the carry and the rest is the result.
Case 2 :
If the final carry is not generated, result obtained in step 2
is negative and in the 2’s complement form.
Subtraction using 2’s complement
Using 2’s complement form
1. Perform (1001) 2 - (0100) 2
2. Perform (0110) 2 - (1011) 2
Class Work
Using 2’s complement form
1. Perform (0100) 2 - (0110) 2
2. Perform (10110) 2 - (1111) 2
Binary Coded Decimal (BCD Code)
Code: When numbers are letters are represented by specific group of
symbols then we say the numbers and letters are encoded and the
group of symbols is known as code.
Binary Coded Decimal is a way to express each of the decimal digits
with a binary code.
For 10 decimal numbers there are 10 code groups in the BCD system
Because we like to read and write in decimal, the BCD code provides
an excellent interface to binary systems.
Example of BCD: 8421 code, 2421 code, etc
The 8421 Code (BCD Code)
Each decimal digit, 0 to 9, is represented
by a binary code of four bits
The designation 8421 indicates the binary
weights of the four bits
The ease of conversion between 8421
code numbers and the familiar decimal
number is the main advantage of this
code.
A number with k decimal digits will
require 4k bits in BCD.
Invalid Codes: The binary combinations
1010 through 1111 are not used and have
no meaning in BCD.
Binary Coded Decimal (BCD Code)
• Example:
• Consider decimal 185 and its corresponding value in BCD and
binary:
• Workout yourself:
1. (2469) 10 = ( ? ) BCD
2. (1001010001110000) BCD = ( ? ) 10
BCD Addition
Step 1: Add the two BCD numbers, using the rule for binary addition
Step 2: If a 4-bit sum is equal to or less than 9, it is a valid BCD
number
Step 3: If a 4-bit sum is greater than 9, or if a carry out of the 4-bit
group is generated, it is an invalid result. Add 6 (0110) to the 4-bit
sum in order to skip the six 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
BCD Addition
Add the following BCD numbers
1. 0011 + 0100 2. 010001010000 + 010000010111
3. 1001 + 0100
BCD Addition
Add the following BCD numbers
4. 1001 + 1001
BCD Addition
Add the following BCD numbers
5. 01100111 + 01010011
Digital Codes
Many specialized codes are used in digital systems.
Some codes are strictly numeric, like BCD, and others
are alphanumeric; that is, they are used to represent
numbers, letters, symbols, and instructions, ASCII code
Gray Code
Gray code is unweighted and is not an arithmetic
code; that is to say there are no specific weight
assigned to the bit positions.
Important feature: It exhibits only a single bit change
from one code word to the next in sequence
This property is important in many applications, such
as shaft position encoders, where error susceptibility
increases with the number of bit changes between
adjacent numbers in sequence.
Binary to Gray Code Conversion
Step 1: The MSB in the gray code is the same as the
corresponding MSB in the binary number.
Step 2: Going from left to right, add each adjacent
pair of binary code bits to get the next gray code bit.
Discard carries
For example: conversion of binary number 10110 to gray code
Gray to Binary Code Conversion
Step 1: The MSB in the binary number is the same as
the corresponding MSB in the gray code.
Step 2: Add each binary code bit generated to the
gray code in the next adjacent position. Discard carries
For example: conversion of gray code 11011 to binary number
Examples:
Convert the binary number 11000110 to gray code
Convert the gray code 10101111 to binary number
Four Bit Gray Code
Excess 3 Code
Excess-3 is an unweighted code in which each coded
combination is obtained from the corresponding BCD
code plus 3
Decimal 8421 Code (BCD) Add Excess-3
0011
The only unweighted code that is self complementing
in nature
Used in some old computers for the self
complementing property.
Other Decimal Codes
Alphanumeric codes
In order to communicate, not only numbers, we also
require letters and symbols.
Alphanumeric codes are codes that represent
numbers and alphabetic characters.
At a minimum , an alphanumeric code must represent
10 decimal digits and 26 letters, for a total of 36 items.
That is to say, this number requires 6 bits in each code
combination
ASCII Code
American Standard Code for Information Interchange
Universally accepted alphanumeric code
Has 128 characters and symbols represented by a 7-
bit binary number
7 bits of code are designated by b1 through b7 with b7
as MSB
Contains 94 graphic characters that can be printed
and 34 nonprinting characters for various control
functions
ASCII Code
Graphic characters: 26 uppercase letters, 26
lowercase letters, 10 numerals, and 32 special
printable characters (!, %, *, $).
Control characters are used for arranging the printed
text into a prescribed format
THANK YOU
Have a GOOD DAY