0% found this document useful (0 votes)
32 views12 pages

09 CALD Lec 09 Binary Codes, Gray Code

This document discusses binary subtraction and binary codes. [1] It explains how subtraction can be performed by converting it to addition by taking the 2's complement of the subtrahend. [2] It also discusses various binary codes including binary coded decimal (BCD) which represents each decimal digit with 4 bits. [3] BCD addition requires adding 6 to results that are greater than 1001 to obtain a valid BCD value and account for carries between digits.

Uploaded by

Andrew Olsen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views12 pages

09 CALD Lec 09 Binary Codes, Gray Code

This document discusses binary subtraction and binary codes. [1] It explains how subtraction can be performed by converting it to addition by taking the 2's complement of the subtrahend. [2] It also discusses various binary codes including binary coded decimal (BCD) which represents each decimal digit with 4 bits. [3] BCD addition requires adding 6 to results that are greater than 1001 to obtain a valid BCD value and account for carries between digits.

Uploaded by

Andrew Olsen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Lecture No 09 : Binary Subtraction, Binary

Codes
BESE-13AB, Spring 2023
Dated 27 February, 2023

By Nasir Mahmood
[email protected]
[email protected]

1
Example Arithmetic (Signed 2’s Complement)

Arithmetic 9 and 11

Add -100 and -56

2
Arithmetic Subtraction

● Subtraction can be performed by simply converting the


equation into an addition formula.
● Take the 2’s complement of the subtrahend (including the sign bit) and add
it to the minuend (including the sign bit)
● A carry out of the sign bit position is discarded
● Note: Subtraction operation can be changed to an addition operation if the
sign of the subtrahend is changed. This is easily done by taking it’s 2’s
complement

3
Example

● Consider the subtraction (–6) –(–13) = +7


● In binary with eight bits the same is written as (11111010 –
11110011)

● This subtraction is changed to addition by taking 2’s


complement of the subtrahend (– 13) to give (+ 13)

● In binary this is 11111010 + 00001101 = 100000111


● Removing the end carry, we obtain the correct answer:
00000111(+7)

4
Binary Codes
● All symbols in a computer must be represented by a
binary code (binary representation).

● An n-bit binary code is a group of n bits that can represent


up to 2n distinct combinations of 1’s and 0’s.
● Each distinct combination represents a single symbol in the computer.

5
BCD Code (8 4 2 1)

● The most common representation for


binary digits is the binary coded
decimal (BCD) form which is a binary
assignment of the decimal numbers.
● This code is the simplest, most intuitive
binary code for decimal digits and uses the
same weights as a binary number, but only
encodes the first ten values from 0 to 9 (6 out
of 16 possible combinations remains
unassigned ).
● A number with k distinct decimal digits will
require 4k bits in BCD.
● Each digit of a decimal value is converted to
its respective binary representation.
● BCD number needs more bits than its
equivalent binary value?

6
Multi-Digit BCD

7
BCD Addition
● BCD only represents each of the decimal digitals 0 through
9 as a single 4-bit binary value.
● When adding two BCD values, if the sum is equal to or less
than 1001 (9), the corresponding BCD value is correct.
● However, when the binary sum is greater or equal to 1010
(10), the result is an invalid BCD value.
● To overcome the invalid BCD value add 0110 (6) to the result to obtain the
BCD representation and also produces a carry as required.
● The use of 0110 (6) works because the difference between a carry in the
most significant bit position of the binary sum and a decimal carry differ
by 16-10 = 6.

8
BCD Addition Examples

9
Multi-Digit BCD Addition
Add 295 and 635 in BCD

10
BCD Arithmetic
● BCD arithmetic involving negative numbers uses the 10’s complement for
representing the negative numbers including the sign digit.
● 0 (0000) represents a positive sign and 9 (1001) represents a negative sign

● As an example, imagine we want to add


(+257) + (-160) = +97

● Note: To obtain 10’s complement of a BCD number, we first take the 9’s complement (by
subtraction of each digit from 9) and then add one to least significant digit

11
D
End of Lecture

12

You might also like