0% found this document useful (0 votes)
12 views6 pages

Binary Arithmetic

This document covers the concept of binary-coded decimal (BCD) representation, detailing how decimal digits are converted to BCD, and how addition and subtraction operations are performed using BCD. It discusses the advantages and disadvantages of BCD, including its accuracy in representing decimal values and the complexity of operations compared to binary systems. The document also includes practical applications of BCD in computing and highlights its historical significance.

Uploaded by

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

Binary Arithmetic

This document covers the concept of binary-coded decimal (BCD) representation, detailing how decimal digits are converted to BCD, and how addition and subtraction operations are performed using BCD. It discusses the advantages and disadvantages of BCD, including its accuracy in representing decimal values and the complexity of operations compared to binary systems. The document also includes practical applications of BCD in computing and highlights its historical significance.

Uploaded by

Afriam
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Lesson 3

BCD Presentation
Objectives:

 Convert decimal digit to binary-coded decimal (BCD);


 Calculate addition and subtraction with BCD;
 Distinguish the advantages and disadvantage of BCD.

Readings:

BCD representation
In computing and electronic systems, binary-coded decimal (BCD) is a class of binary
encodings of decimal numbers where each decimal digit is represented by a fixed number of bits,
usually four or eight, although other sizes (such as six bits) have been used historically. Special
bit patterns are sometimes used for a sign or for other indications (e.g., error or overflow).
In byte-oriented systems (i.e. most modern computers), the term uncompressed BCD usually
implies a full byte for each digit (often including a sign), whereas packed BCD typically encodes
two decimal digits within a single byte by taking advantage of the fact that four bits are enough
to represent the range 0 to 9. The precise 4-bit encoding may vary however, for technical
reasons, see Excess-3 for instance.
BCD's main virtue is a more accurate representation and rounding of decimal quantities as well
as an ease of conversion into human-readable representations. As compared to binary positional
systems, BCD's principal drawbacks are a small increase in the complexity of the circuitsneeded
to implement basic arithmetics and a slightly less dense storage.
BCD was used in many early decimal computers. Although BCD is not as widely used as in the
past, decimal fixed-point and floating-point formats are still important and continue to be used in
financial, commercial, and industrial computing, where subtle conversion and rounding errors
that are inherent to floating point binary representations cannot be tolerated.
As described in the introduction, BCD takes advantage of the fact that any one decimal numeral
can be represented by a four-bit pattern:
Decimal BCD
Digit 8421
0 0000
1 0001
2 0010
3 0011
4 0100
5 0101
6 0110
7 0111
8 1000
9 1001
As most computers store data in 8-bit bytes, it is possible to use one of the following methods to
encode a BCD number:

Uncompressed: each numeral is encoded into one byte, with four bits representing the
Computer Organization with Assembly Language Prepared by:
1ST SEMESTER – S.Y. 2021 – 2022 mja
CIITE
1
numeral and the remaining bits having no significance.
Packed: two numerals are encoded into a single byte, with one numeral in the least
significant nibble (bits 0 through 3) and the other numeral in the most significant nibble (bits
4 through 7).
As an example, encoding the decimal number 91 using uncompressed BCD results in the
following binary pattern of two bytes:

Decimal: 9 1
Binary : 0000 1001 0000 0001

In packed BCD, the same number would fit into a single byte:

Decimal: 9 1
Binary : 1001 0001

Hence the numerical range for one uncompressed BCD byte is zero through nine inclusive,
whereas the range for one packed BCD is zero through ninety-nine inclusive.
To represent numbers larger than the range of a single byte any number of contiguous bytes may
be used. For example, to represent the decimal number 12345 in packed BCD, using big-
endian format, a program would encode as follows:

Decimal: 1 2 3 4 5
Binary : 0000 0001 0010 0011 0100 0101

Note that the most significant nibble of the most significant byte is zero, implying that the
number is in actuality 012345. Also note how packed BCD is more efficient in storage usage as
compared to uncompressed BCD; encoding the same number in uncompressed format would
consume 100 percent more storage.
Shifting and masking operations are used to pack or unpack a packed BCD digit. Other logical
operations are used to convert a numeral to its equivalent bit pattern or reverse the process.

Addition with BCD

It is possible to perform addition in BCD by first adding in binary, and then converting to BCD
afterwards. Conversion of the simple sum of two digits can be done by adding 6 (that is, 16 – 10)
when the five-bit result of adding a pair of digits has a value greater than 9. For example:

1001 + 1000 = 10001


9 + 8 = 17

Note that 10001 is the binary, not decimal, representation of the desired result. In BCD as in
decimal, there cannot exist a value greater than 9 (1001) per digit. To correct this, 6 (0110) is
added to that sum and then the result is treated as two nibbles:

10001 + 0110 = 00010111 => 0001 0111


17 + 6 = 23 1 7

The two nibbles of the result, 0001 and 0111, correspond to the digits "1" and "7". This yields
"17" in BCD, which is the correct result.

Computer Organization with Assembly Language Prepared by:


1ST SEMESTER – S.Y. 2021 – 2022 mja
CIITE
2
This technique can be extended to adding multiple digits by adding in groups from right to left,
propagating the second digit as a carry, always comparing the 5-bit result of each digit-pair sum
to 9. Some CPUs provide a half-carry flag to facilitate BCD arithmetic adjustments following
binary addition and subtraction operations.

Subtraction with BCD


Subtraction is done by adding the ten's complement of the subtrahend. To represent the sign of a
number in BCD, the number 0000 is used to represent a positive number, and 1001 is used to
represent a negative number. The remaining 14 combinations are invalid signs. To illustrate
signed BCD subtraction, consider the following problem: 357 − 432.
In signed BCD, 357 is 0000 0011 0101 0111. The ten's complement of 432 can be obtained by
taking the nine's complement of 432, and then adding one. So, 999 − 432 = 567, and 567 + 1 =
568. By preceding 568 in BCD by the negative sign code, the number −432 can be represented.
So, −432 in signed BCD is 1001 0101 0110 1000.
Now that both numbers are represented in signed BCD, they can be added together:

0000 0011 0101 0111 + 1001 0101 0110 1000 = 1001 1000 1011 1111
0 3 5 7 + 9 5 6 8 = 9 8 11 15

Since BCD is a form of decimal representation, several of the digit sums above are invalid. In the
event that an invalid entry (any BCD digit greater than 1001) exists, 6 is added to generate a
carry bit and cause the sum to become a valid entry. The reason for adding 6 is that there are 16
possible 4-bit BCD values (since 24 = 16), but only 10 values are valid (0000 through 1001). So
adding 6 to the invalid entries results in the following:

1001 1000 1011 1111 + 0000 0000 0110 0110 = 1001 1001 0010 0101
9 8 11 15 + 0 0 6 6 = 9 9 2 5

Thus the result of the subtraction is 1001 1001 0010 0101 (-925). To check the answer, note that
the first bit is the sign bit, which is negative. This seems to be correct, since 357 − 432 should
result in a negative number. To check the rest of the digits, represent them in decimal. 1001 0010
0101 is 925. The ten's complement of 925 is 1000 − 925 = 999 − 925 + 1 = 074 + 1 = 75, so the
calculated answer is −75. To check, perform standard subtraction to verify that 357 − 432 is −75.
Note that in the event that there are a different number of nibbles being added together (such as
1053 − 122), the number with the fewest number of digits must first be padded with zeros before
taking the ten's complement or subtracting. So, with 1053 − 122, 122 would have to first be
represented as 0122, and the ten's complement of 0122 would have to be calculated.
Advantages
Many non-integral values, such as decimal 0.2, have an infinite place-value representation in
binary (.001100110011...) but have a finite place-value in binary-coded decimal (0.0010).
Consequently a system based on binary-coded decimal representations of decimal fractions
avoids errors representing and calculating such values.

Scaling by a factor of 10 (or a power of 10) is simple; this is useful when a decimal
scaling factor is needed to represent a non-integer quantity (e.g., in financial calculations)
Rounding at a decimal digit boundary is simpler. Addition and subtraction in decimal
does not require rounding.
Alignment of two decimal numbers (for example 1.3 + 27.08) is a simple, exact, shift.
Conversion to a character form or for display (e.g., to a text-based format such as XML,
Computer Organization with Assembly Language Prepared by:
1ST SEMESTER – S.Y. 2021 – 2022 mja
CIITE
3
or to drive signals for a seven-segment display) is a simple per-digit mapping, and can be
done in linear (O(n)) time. Conversion from pure binary involves relatively complex logic
that spans digits, and for large numbers no linear-time conversion algorithm is known
(see Binary numeral system).

Disadvantages

Some operations are more complex to implement. Adders require extra logic to cause
them to wrap and generate a carry early. 15–20 percent more circuitry is needed for BCD
add compared to pure binary.[citation needed] Multiplication requires the use of algorithms that
are somewhat more complex than shift-mask-add (a binary multiplication, requiring binary
shifts and adds or the equivalent, per-digit or group of digits is required)
Standard BCD requires four bits per digit, roughly 20 percent more space than a binary
encoding (the ratio of 4 bits to log210 bits is 1.204). When packed so that three digits are
encoded in ten bits, the storage overhead is greatly reduced, at the expense of an encoding
that is unaligned with the 8-bit byte boundaries common on existing hardware, resulting in
slower implementations on these systems.
Practical existing implementations of BCD are typically slower than operations on binary
representations, especially on embedded systems,[citation needed] due to limited processor support
for native BCD operations.

Application
The BIOS in many personal computers stores the date and time in BCD because
the MC6818 real-time clock chip used in the original IBM PC AT motherboard provided the
time encoded in BCD. This form is easily converted into ASCII for display.[8]
The Atari 8-bit family of computers used BCD to implement floating-point algorithms.
The MOS 6502 processor used has a BCD mode that affects the addition and subtraction
instructions.
Early models of the PlayStation 3 store the date and time in BCD. This led to a worldwide
outage of the console on 1 March 2010. The last two digits of the year stored as BCD were
misinterpreted as 16 causing an error in the unit's date, rendering most functions inoperable. This
has been referred to as the Year 2010 Problem

References:

Books
Revano, Teodoro F. Jr (2018), Computer System Organization with Assembly Language.
Minshapers Co., Inc. Rm,108,ICP Bldg., Recoletos St., Intramuros, Manila

Website

[Link]
[Link]

Computer Organization with Assembly Language Prepared by:


1ST SEMESTER – S.Y. 2021 – 2022 mja
CIITE
4
Lesson 5: Activity 1
BCD Presentation

Name: Score:
Course and Year: Date:
Problem solving. Solve the following questions in the space provided and encircle your correct answer.
Addition with BCD:
1. Decimal: 8 + 7 = 15
Binary:

2. Decimal: 15 + 8 = 23
Binary:

3. Decimal: 5 + 9 = 14
Binary:

Subtraction with BCD:


1. Decimal: 3 5 7 + 5 6 8 =
Binary:

2. Decimal: 1 2 3 + 4 5 6 =
Binary:

Computer Organization with Assembly Language Prepared by:


1ST SEMESTER – S.Y. 2021 – 2022 REYMARC B. CATUBAG
CIITE
5
Lesson 5: Activity 1
BCD Presentation

Name: Score:
Course and Year: Date:
Answer the following questions in the space provided.
1. Enumerate the advantage and disadvantage of BCD Presentation at least
8 sentences in your own words.

Computer Organization with Assembly Language Prepared by:


1ST SEMESTER – S.Y. 2021 – 2022 REYMARC B. CATUBAG
CIITE
6

You might also like