0% found this document useful (0 votes)
148 views2 pages

ALP To Convert Two Digit Packed BCD To Unpacked BCD

The document discusses packed and unpacked BCD formats, how to represent decimal numbers in binary, and provides a logic to convert between two digit packed BCD and unpacked BCD by masking and rotating bits.

Uploaded by

Deep Chavan
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)
148 views2 pages

ALP To Convert Two Digit Packed BCD To Unpacked BCD

The document discusses packed and unpacked BCD formats, how to represent decimal numbers in binary, and provides a logic to convert between two digit packed BCD and unpacked BCD by masking and rotating bits.

Uploaded by

Deep Chavan
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/ 2

ALP to convert two digit Packed BCD to Unpacked BCD

What is BCD?
BCD or Binary-Coded Decimal is a system of representing numerals that assigns a four-
digit binary code to each digit 0 through 9 in a decimal (base 10) number. In BCD system
the decimal numerals [0-9] are represented by four bit binary as follows.
Digit BCD
0 0000
1 0001
2 0010
3 0011
4 0100
5 0101
6 0110
7 0111
8 1000
9 1001

In the decimal system, all numbers larger than 9 have two or more digits. In the binary-
coded decimal system, each digit is encoded separately. The full number is first
segregated into its individual digits. These digits are then represented by their equivalent
4-bit binary-coded decimal codes as shown in above table.
Invalid BCD:
The invalid BCD numbers: 1010, 1011, 1100, 1101, 1110, 1111.
Unpacked BCD
In Unpacked BCD, only one digit is stored per byte.
Decimal Unpacked BCD
2 0000 0010
7 0000 0111
9 0000 1001
Packed BCD:
In the case of packed BCD numbers, two BCD digits are stored per byte.
Decimal BCD
23 0010 0011
72 0111 0010
94 1001 0100
Logic:
Consider you want to convert 1001 1000 (i.e. packed BCD 98) to unpacked BCD. The
expected result is 0000 1001 (unpacked BCD 9) and 0000 1000 (unpacked BCD).
1. Mask lower nibble (four bits) of the packed BCD number. (1001 0000)
2. Rotate right by 4 bits. (0000 1001)
3. Store the upper unpacked BCD digit.
4. Mask upper nibble (four bits) of the packed BCD number. (0000 1000)
5. Store the lower unpacked BCD digit.
Suggested instructions:
 AND instruction for masking
 ROR for rotate

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy