<s>
In	O
computing	O
and	O
electronic	O
systems	O
,	O
binary-coded	O
decimal	B-Application
(	O
BCD	O
)	O
is	O
a	O
class	O
of	O
binary	B-Algorithm
encodings	I-Algorithm
of	O
decimal	B-Application
numbers	O
where	O
each	O
digit	O
is	O
represented	O
by	O
a	O
fixed	O
number	O
of	O
bits	O
,	O
usually	O
four	O
or	O
eight	O
.	O
</s>
<s>
error	O
or	O
overflow	B-Algorithm
)	O
.	O
</s>
<s>
In	O
byte-oriented	O
systems	O
(	O
i.e.	O
</s>
<s>
most	O
modern	O
computers	O
)	O
,	O
the	O
term	O
unpacked	O
BCD	O
usually	O
implies	O
a	O
full	O
byte	B-Application
for	O
each	O
digit	O
(	O
often	O
including	O
a	O
sign	O
)	O
,	O
whereas	O
packed	O
BCD	O
typically	O
encodes	O
two	O
digits	O
within	O
a	O
single	O
byte	B-Application
by	O
taking	O
advantage	O
of	O
the	O
fact	O
that	O
four	O
bits	O
are	O
enough	O
to	O
represent	O
the	O
range	O
0	O
to	O
9	O
.	O
</s>
<s>
The	O
ten	O
states	O
representing	O
a	O
BCD	O
digit	O
are	O
sometimes	O
called	O
tetrades	O
(	O
for	O
the	O
nibble	O
typically	O
needed	O
to	O
hold	O
them	O
is	O
also	O
known	O
as	O
a	O
tetrade	O
)	O
while	O
the	O
unused	O
,	O
do	O
n't	O
care-states	O
are	O
named	O
,	O
pseudo-decimals	O
or	O
pseudo-decimal	O
digits	O
.	O
</s>
<s>
BCD	O
's	O
main	O
virtue	O
,	O
in	O
comparison	O
to	O
binary	O
positional	O
systems	O
,	O
is	O
its	O
more	O
accurate	O
representation	O
and	O
rounding	B-Algorithm
of	O
decimal	B-Application
quantities	O
,	O
as	O
well	O
as	O
its	O
ease	O
of	O
conversion	O
into	O
conventional	O
human-readable	O
representations	O
.	O
</s>
<s>
BCD	O
was	O
used	O
in	O
many	O
early	O
decimal	B-Device
computers	I-Device
,	O
and	O
is	O
implemented	O
in	O
the	O
instruction	B-General_Concept
set	I-General_Concept
of	O
machines	O
such	O
as	O
the	O
IBM	B-Application
System/360	I-Application
series	O
and	O
its	O
descendants	O
,	O
Digital	O
Equipment	O
Corporation	O
's	O
VAX	B-Device
,	O
the	O
Burroughs	B-Device
B1700	I-Device
,	O
and	O
the	O
Motorola	O
68000-series	O
processors	O
.	O
</s>
<s>
BCD	O
per	O
se	O
is	O
not	O
as	O
widely	O
used	O
as	O
in	O
the	O
past	O
,	O
and	O
is	O
unavailable	O
or	O
limited	O
in	O
newer	O
instruction	B-General_Concept
sets	I-General_Concept
(	O
e.g.	O
,	O
ARM	B-Architecture
;	O
x86	B-Operating_System
in	O
long	B-Application
mode	I-Application
)	O
.	O
</s>
<s>
However	O
,	O
decimal	B-Application
fixed-point	O
and	O
decimal	B-Application
floating-point	B-Algorithm
formats	I-Algorithm
are	O
still	O
important	O
and	O
continue	O
to	O
be	O
used	O
in	O
financial	O
,	O
commercial	O
,	O
and	O
industrial	O
computing	O
,	O
where	O
the	O
subtle	O
conversion	O
and	O
fractional	O
rounding	B-Algorithm
errors	I-Algorithm
that	O
are	O
inherent	O
in	O
binary	B-Algorithm
floating	I-Algorithm
point	I-Algorithm
formats	O
cannot	O
be	O
tolerated	O
.	O
</s>
<s>
BCD	O
takes	O
advantage	O
of	O
the	O
fact	O
that	O
any	O
one	O
decimal	B-Application
numeral	O
can	O
be	O
represented	O
by	O
a	O
four-bit	O
pattern	O
.	O
</s>
<s>
The	O
most	O
obvious	O
way	O
of	O
encoding	O
digits	O
is	O
Natural	O
BCD	O
(	O
NBCD	O
)	O
,	O
where	O
each	O
decimal	B-Application
digit	O
is	O
represented	O
by	O
its	O
corresponding	O
four-bit	O
binary	O
value	O
,	O
as	O
shown	O
in	O
the	O
following	O
table	O
.	O
</s>
<s>
This	O
scheme	O
can	O
also	O
be	O
referred	O
to	O
as	O
Simple	O
Binary-Coded	O
Decimal	B-Application
(	O
SBCD	O
)	O
or	O
BCD	O
8421	O
,	O
and	O
is	O
the	O
most	O
common	O
encoding	O
.	O
</s>
<s>
The	O
following	O
table	O
represents	O
decimal	B-Application
digits	O
from	O
0	O
to	O
9	O
in	O
various	O
BCD	O
encoding	O
systems	O
.	O
</s>
<s>
Both	O
ASCII	B-Protocol
and	O
EBCDIC	B-Language
character	O
codes	O
for	O
the	O
digits	O
,	O
which	O
are	O
examples	O
of	O
zoned	O
BCD	O
,	O
are	O
also	O
shown	O
.	O
</s>
<s>
As	O
most	O
computers	O
deal	O
with	O
data	O
in	O
8-bit	O
bytes	B-Application
,	O
it	O
is	O
possible	O
to	O
use	O
one	O
of	O
the	O
following	O
methods	O
to	O
encode	O
a	O
BCD	O
number	O
:	O
</s>
<s>
Unpacked	O
:	O
Each	O
decimal	B-Application
digit	O
is	O
encoded	O
into	O
one	O
byte	B-Application
,	O
with	O
four	O
bits	O
representing	O
the	O
number	O
and	O
the	O
remaining	O
bits	O
having	O
no	O
significance	O
.	O
</s>
<s>
Packed	O
:	O
Two	O
decimal	B-Application
digits	O
are	O
encoded	O
into	O
a	O
single	O
byte	B-Application
,	O
with	O
one	O
digit	O
in	O
the	O
least	O
significant	O
nibble	O
(	O
bits	O
0	O
through	O
3	O
)	O
and	O
the	O
other	O
numeral	O
in	O
the	O
most	O
significant	O
nibble	O
(	O
bits	O
4	O
through	O
7	O
)	O
.	O
</s>
<s>
As	O
an	O
example	O
,	O
encoding	O
the	O
decimal	B-Application
number	O
91	O
using	O
unpacked	O
BCD	O
results	O
in	O
the	O
following	O
binary	O
pattern	O
of	O
two	O
bytes	B-Application
:	O
</s>
<s>
In	O
packed	O
BCD	O
,	O
the	O
same	O
number	O
would	O
fit	O
into	O
a	O
single	O
byte	B-Application
:	O
</s>
<s>
Hence	O
the	O
numerical	O
range	O
for	O
one	O
unpacked	O
BCD	O
byte	B-Application
is	O
zero	O
through	O
nine	O
inclusive	O
,	O
whereas	O
the	O
range	O
for	O
one	O
packed	O
BCD	O
byte	B-Application
is	O
zero	O
through	O
ninety-nine	O
inclusive	O
.	O
</s>
<s>
To	O
represent	O
numbers	O
larger	O
than	O
the	O
range	O
of	O
a	O
single	O
byte	B-Application
any	O
number	O
of	O
contiguous	O
bytes	B-Application
may	O
be	O
used	O
.	O
</s>
<s>
For	O
example	O
,	O
to	O
represent	O
the	O
decimal	B-Application
number	O
12345	O
in	O
packed	O
BCD	O
,	O
using	O
big-endian	O
format	O
,	O
a	O
program	O
would	O
encode	O
as	O
follows	O
:	O
</s>
<s>
Here	O
,	O
the	O
most	O
significant	O
nibble	O
of	O
the	O
most	O
significant	O
byte	B-Application
has	O
been	O
encoded	O
as	O
zero	O
,	O
so	O
the	O
number	O
is	O
stored	O
as	O
012345	O
(	O
but	O
formatting	O
routines	O
might	O
replace	O
or	O
remove	O
leading	O
zeros	O
)	O
.	O
</s>
<s>
In	O
packed	O
BCD	O
(	O
or	O
simply	O
packed	O
decimal	B-Application
)	O
,	O
each	O
nibble	O
represent	O
a	O
decimal	B-Application
digit	O
.	O
</s>
<s>
with	O
the	O
more	O
significant	O
digit	O
in	O
the	O
upper	O
half	O
of	O
each	O
byte	B-Application
,	O
and	O
with	O
the	O
leftmost	O
byte	B-Application
(	O
residing	O
at	O
the	O
lowest	O
memory	O
address	O
)	O
containing	O
the	O
most	O
significant	O
digits	O
of	O
the	O
packed	O
decimal	B-Application
value	O
.	O
</s>
<s>
The	O
lower	O
nibble	O
of	O
the	O
rightmost	O
byte	B-Application
is	O
usually	O
used	O
as	O
the	O
sign	O
flag	O
,	O
although	O
some	O
unsigned	B-Algorithm
representations	O
lack	O
a	O
sign	O
flag	O
.	O
</s>
<s>
As	O
an	O
example	O
,	O
a	O
4-byte	O
value	O
consists	O
of	O
8	O
nibbles	O
,	O
wherein	O
the	O
upper	O
7	O
nibbles	O
store	O
the	O
digits	O
of	O
a	O
7-digit	O
decimal	B-Application
value	O
,	O
and	O
the	O
lowest	O
nibble	O
indicates	O
the	O
sign	O
of	O
the	O
decimal	B-Application
integer	O
value	O
.	O
</s>
<s>
Standard	O
sign	O
values	O
are	O
1100	O
(	O
hex	O
C	B-Language
)	O
for	O
positive	O
( +	O
)	O
and	O
1101	O
(	O
D	O
)	O
for	O
negative	O
( −	O
)	O
.	O
</s>
<s>
This	O
convention	O
comes	O
from	O
the	O
zone	O
field	O
for	O
EBCDIC	B-Language
characters	O
and	O
the	O
signed	B-Device
overpunch	I-Device
representation	O
.	O
</s>
<s>
IBM	B-Application
System/360	I-Application
processors	O
will	O
use	O
the	O
1010	O
(	O
A	O
)	O
and	O
1011	O
(	O
B	O
)	O
signs	O
if	O
the	O
A	O
bit	O
is	O
set	O
in	O
the	O
PSW	O
,	O
for	O
the	O
ASCII-8	O
standard	O
that	O
never	O
passed	O
.	O
</s>
<s>
Most	O
implementations	O
also	O
provide	O
unsigned	B-Algorithm
BCD	O
values	O
with	O
a	O
sign	O
nibble	O
of	O
1111	O
(	O
F	O
)	O
.	O
</s>
<s>
These	O
match	O
the	O
EBCDIC	B-Language
zone	O
for	O
digits	O
without	O
a	O
sign	O
overpunch	B-Architecture
.	O
</s>
<s>
Burroughs	O
systems	O
used	O
1101	O
(	O
D	O
)	O
for	O
negative	O
,	O
and	O
any	O
other	O
value	O
is	O
considered	O
a	O
positive	O
sign	O
value	O
(	O
the	O
processors	O
will	O
normalize	O
a	O
positive	O
sign	O
to	O
1100	O
(	O
C	B-Language
)	O
)	O
.	O
</s>
<s>
No	O
matter	O
how	O
many	O
bytes	B-Application
wide	O
a	O
word	O
is	O
,	O
there	O
is	O
always	O
an	O
even	O
number	O
of	O
nibbles	O
because	O
each	O
byte	B-Application
has	O
two	O
of	O
them	O
.	O
</s>
<s>
Therefore	O
,	O
a	O
word	O
of	O
n	O
bytes	B-Application
can	O
contain	O
up	O
to	O
(	O
2n	O
)	O
−1	O
decimal	B-Application
digits	O
,	O
which	O
is	O
always	O
an	O
odd	O
number	O
of	O
digits	O
.	O
</s>
<s>
A	O
decimal	B-Application
number	O
with	O
d	O
digits	O
requires	O
(	O
d+1	O
)	O
bytes	B-Application
of	O
storage	O
space	O
.	O
</s>
<s>
For	O
example	O
,	O
a	O
4-byte	O
(	O
32-bit	O
)	O
word	O
can	O
hold	O
seven	O
decimal	B-Application
digits	O
plus	O
a	O
sign	O
and	O
can	O
represent	O
values	O
ranging	O
from	O
±	O
9,999,999	O
.	O
</s>
<s>
Like	O
character	O
strings	O
,	O
the	O
first	O
byte	B-Application
of	O
the	O
packed	O
decimal	B-Application
that	O
with	O
the	O
most	O
significant	O
two	O
digits	O
is	O
usually	O
stored	O
in	O
the	O
lowest	O
address	O
in	O
memory	O
,	O
independent	O
of	O
the	O
endianness	O
of	O
the	O
machine	O
.	O
</s>
<s>
In	O
contrast	O
,	O
a	O
4-byte	O
binary	O
two	B-General_Concept
's	I-General_Concept
complement	I-General_Concept
integer	O
can	O
represent	O
values	O
from	O
−	O
2,147,483,648	O
to	O
+	O
2,147,483,647	O
.	O
</s>
<s>
While	O
packed	O
BCD	O
does	O
not	O
make	O
optimal	O
use	O
of	O
storage	O
(	O
using	O
about	O
20%	O
more	O
memory	O
than	O
binary	O
notation	O
to	O
store	O
the	O
same	O
numbers	O
)	O
,	O
conversion	O
to	O
ASCII	B-Protocol
,	O
EBCDIC	B-Language
,	O
or	O
the	O
various	O
encodings	O
of	O
Unicode	O
is	O
made	O
trivial	O
,	O
as	O
no	O
arithmetic	O
operations	O
are	O
required	O
.	O
</s>
<s>
The	O
extra	O
storage	O
requirements	O
are	O
usually	O
offset	O
by	O
the	O
need	O
for	O
the	O
accuracy	O
and	O
compatibility	O
with	O
calculator	O
or	O
hand	O
calculation	O
that	O
fixed-point	O
decimal	B-Application
arithmetic	O
provides	O
.	O
</s>
<s>
Packed	O
BCD	O
is	O
supported	O
in	O
the	O
COBOL	B-Application
programming	I-Application
language	I-Application
as	O
the	O
"	O
COMPUTATIONAL-3	O
"	O
(	O
an	O
IBM	O
extension	O
adopted	O
by	O
many	O
other	O
compiler	O
vendors	O
)	O
or	O
"	O
PACKED-DECIMAL	O
"	O
(	O
part	O
of	O
the	O
1985	O
COBOL	B-Application
standard	O
)	O
data	O
type	O
.	O
</s>
<s>
It	O
is	O
supported	O
in	O
PL/I	B-Language
as	O
"	O
FIXED	O
DECIMAL	B-Application
"	O
.	O
</s>
<s>
Beside	O
the	O
IBM	B-Application
System/360	I-Application
and	O
later	O
compatible	O
mainframes	O
,	O
packed	O
BCD	O
is	O
implemented	O
in	O
the	O
native	O
instruction	B-General_Concept
set	I-General_Concept
of	O
the	O
original	O
VAX	B-Device
processors	O
from	O
Digital	O
Equipment	O
Corporation	O
and	O
some	O
models	O
of	O
the	O
SDS	B-Device
Sigma	I-Device
series	I-Device
mainframes	O
,	O
and	O
is	O
the	O
native	O
format	O
for	O
the	O
Burroughs	O
Corporation	O
Medium	O
Systems	O
line	O
of	O
mainframes	O
(	O
descended	O
from	O
the	O
1950s	O
Electrodata	O
200	O
series	O
)	O
.	O
</s>
<s>
Ten	B-Algorithm
's	I-Algorithm
complement	I-Algorithm
representations	O
for	O
negative	O
numbers	O
offer	O
an	O
alternative	O
approach	O
to	O
encoding	O
the	O
sign	O
of	O
packed	O
(	O
and	O
other	O
)	O
BCD	O
numbers	O
.	O
</s>
<s>
(	O
As	O
with	O
two	B-General_Concept
's	I-General_Concept
complement	I-General_Concept
binary	O
numbers	O
,	O
the	O
range	O
is	O
not	O
symmetric	O
about	O
zero	O
.	O
)	O
</s>
<s>
Fixed-point	O
decimal	B-Application
numbers	O
are	O
supported	O
by	O
some	O
programming	O
languages	O
(	O
such	O
as	O
COBOL	B-Application
and	O
PL/I	B-Language
)	O
.	O
</s>
<s>
These	O
languages	O
allow	O
the	O
programmer	O
to	O
specify	O
an	O
implicit	O
decimal	B-Application
point	O
in	O
front	O
of	O
one	O
of	O
the	O
digits	O
.	O
</s>
<s>
For	O
example	O
,	O
a	O
packed	O
decimal	B-Application
value	O
encoded	O
with	O
the	O
bytes	B-Application
12	O
34	O
56	O
7C	O
represents	O
the	O
fixed-point	O
value	O
+	O
1,234	O
.567	O
when	O
the	O
implied	O
decimal	B-Application
point	O
is	O
located	O
between	O
the	O
fourth	O
and	O
fifth	O
digits	O
:	O
</s>
<s>
The	O
decimal	B-Application
point	O
is	O
not	O
actually	O
stored	O
in	O
memory	O
,	O
as	O
the	O
packed	O
BCD	O
storage	O
format	O
does	O
not	O
provide	O
for	O
it	O
.	O
</s>
<s>
If	O
a	O
decimal	B-Application
digit	O
requires	O
four	O
bits	O
,	O
then	O
three	O
decimal	B-Application
digits	O
require	O
12	O
bits	O
.	O
</s>
<s>
However	O
,	O
since	O
210	O
(	O
1,024	O
)	O
is	O
greater	O
than	O
103	O
(	O
1,000	O
)	O
,	O
if	O
three	O
decimal	B-Application
digits	O
are	O
encoded	O
together	O
,	O
only	O
10	O
bits	O
are	O
needed	O
.	O
</s>
<s>
Two	O
such	O
encodings	O
are	O
Chen	O
–	O
Ho	O
encoding	O
and	O
densely	O
packed	O
decimal	B-Application
(	O
DPD	O
)	O
.	O
</s>
<s>
Some	O
implementations	O
,	O
for	O
example	O
IBM	O
mainframe	O
systems	O
,	O
support	O
zoned	O
decimal	B-Application
numeric	B-Algorithm
representations	O
.	O
</s>
<s>
Each	O
decimal	B-Application
digit	O
is	O
stored	O
in	O
one	O
byte	B-Application
,	O
with	O
the	O
lower	O
four	O
bits	O
encoding	O
the	O
digit	O
in	O
BCD	O
form	O
.	O
</s>
<s>
The	O
upper	O
four	O
bits	O
,	O
called	O
the	O
"	O
zone	O
"	O
bits	O
,	O
are	O
usually	O
set	O
to	O
a	O
fixed	O
value	O
so	O
that	O
the	O
byte	B-Application
holds	O
a	O
character	O
value	O
corresponding	O
to	O
the	O
digit	O
.	O
</s>
<s>
EBCDIC	B-Language
systems	O
use	O
a	O
zone	O
value	O
of	O
1111	O
(	O
hex	O
F	O
)	O
;	O
this	O
yields	O
bytes	B-Application
in	O
the	O
range	O
F0	O
to	O
F9	O
(	O
hex	O
)	O
,	O
which	O
are	O
the	O
EBCDIC	B-Language
codes	O
for	O
the	O
characters	O
"	O
0	O
"	O
through	O
"	O
9	O
"	O
.	O
</s>
<s>
Similarly	O
,	O
ASCII	B-Protocol
systems	O
use	O
a	O
zone	O
value	O
of	O
0011	O
(	O
hex	O
3	O
)	O
,	O
giving	O
character	O
codes	O
30	O
to	O
39	O
(	O
hex	O
)	O
.	O
</s>
<s>
For	O
signed	O
zoned	O
decimal	B-Application
values	O
,	O
the	O
rightmost	O
(	O
least	O
significant	O
)	O
zone	O
nibble	O
holds	O
the	O
sign	O
digit	O
,	O
which	O
is	O
the	O
same	O
set	O
of	O
values	O
that	O
are	O
used	O
for	O
signed	O
packed	O
decimal	B-Application
numbers	O
(	O
see	O
above	O
)	O
.	O
</s>
<s>
Thus	O
a	O
zoned	O
decimal	B-Application
value	O
encoded	O
as	O
the	O
hex	O
bytes	B-Application
F1	O
F2	O
D3	O
represents	O
the	O
signed	O
decimal	B-Application
value	O
−123	O
:	O
</s>
<s>
Some	O
languages	O
(	O
such	O
as	O
COBOL	B-Application
and	O
PL/I	B-Language
)	O
directly	O
support	O
fixed-point	O
zoned	O
decimal	B-Application
values	O
,	O
assigning	O
an	O
implicit	O
decimal	B-Application
point	O
at	O
some	O
location	O
between	O
the	O
decimal	B-Application
digits	O
of	O
a	O
number	O
.	O
</s>
<s>
For	O
example	O
,	O
given	O
a	O
six-byte	O
signed	O
zoned	O
decimal	B-Application
value	O
with	O
an	O
implied	O
decimal	B-Application
point	O
to	O
the	O
right	O
of	O
the	O
fourth	O
digit	O
,	O
the	O
hex	O
bytes	B-Application
F1	O
F2	O
F7	O
F9	O
F5	O
C0	O
represent	O
the	O
value	O
+	O
1,279	O
.50	O
:	O
</s>
<s>
IBM	O
used	O
the	O
terms	O
Binary-Coded	O
Decimal	B-Application
Interchange	O
Code	O
(	O
BCDIC	O
,	O
sometimes	O
just	O
called	O
BCD	O
)	O
,	O
for	O
6-bit	O
alphanumeric	O
codes	O
that	O
represented	O
numbers	O
,	O
upper-case	O
letters	O
and	O
special	O
characters	O
.	O
</s>
<s>
Some	O
variation	O
of	O
BCDIC	O
alphamerics	O
is	O
used	O
in	O
most	O
early	O
IBM	O
computers	O
,	O
including	O
the	O
IBM	B-Device
1620	I-Device
(	O
introduced	O
in	O
1959	O
)	O
,	O
IBM	B-Device
1400	I-Device
series	I-Device
,	O
and	O
non-Decimal	O
Architecture	O
members	O
of	O
the	O
IBM	B-Device
700/7000	I-Device
series	I-Device
.	O
</s>
<s>
The	O
IBM	B-Device
1400	I-Device
series	I-Device
are	O
character-addressable	O
machines	O
,	O
each	O
location	O
being	O
six	O
bits	O
labeled	O
B	O
,	O
A	O
,	O
8	O
,	O
4	O
,	O
2	O
and	O
1	O
,	O
plus	O
an	O
odd	B-Error_Name
parity	I-Error_Name
check	B-Error_Name
bit	I-Error_Name
(	O
C	B-Language
)	O
and	O
a	O
word	O
mark	O
bit	O
(	O
M	O
)	O
.	O
</s>
<s>
For	O
most	O
other	O
characters	O
bits	O
B	O
and	O
A	O
are	O
derived	O
simply	O
from	O
the	O
"	O
12	O
"	O
,	O
"	O
11	O
"	O
,	O
and	O
"	O
0	O
"	O
"	O
zone	O
punches	O
"	O
in	O
the	O
punched	B-Architecture
card	I-Architecture
character	O
code	O
,	O
and	O
bits	O
8	O
through	O
1	O
from	O
the	O
1	O
through	O
9	O
punches	O
.	O
</s>
<s>
Thus	O
the	O
letter	O
A	O
,	O
which	O
is	O
(	O
12	O
,	O
1	O
)	O
in	O
the	O
punched	B-Architecture
card	I-Architecture
format	O
,	O
is	O
encoded	O
(	O
B	O
,	O
A	O
,	O
1	O
)	O
.	O
</s>
<s>
The	O
currency	O
symbol	O
$	O
,	O
(	O
11	O
,	O
8	O
,	O
3	O
)	O
in	O
the	O
punched	B-Architecture
card	I-Architecture
,	O
was	O
encoded	O
in	O
memory	O
as	O
(	O
B	O
,	O
8	O
,	O
2	O
,	O
1	O
)	O
.	O
</s>
<s>
This	O
allows	O
the	O
circuitry	O
to	O
convert	O
between	O
the	O
punched	B-Architecture
card	I-Architecture
format	O
and	O
the	O
internal	O
storage	O
format	O
to	O
be	O
very	O
simple	O
with	O
only	O
a	O
few	O
special	O
cases	O
.	O
</s>
<s>
The	O
memory	O
of	O
the	O
IBM	B-Device
1620	I-Device
is	O
organized	O
into	O
6-bit	O
addressable	O
digits	O
,	O
the	O
usual	O
8	O
,	O
4	O
,	O
2	O
,	O
1	O
plus	O
F	O
,	O
used	O
as	O
a	O
flag	O
bit	O
and	O
C	B-Language
,	O
an	O
odd	B-Error_Name
parity	I-Error_Name
check	B-Error_Name
bit	I-Error_Name
.	O
</s>
<s>
In	O
the	O
Decimal	B-Device
Architecture	I-Device
IBM	B-Device
7070	I-Device
,	O
IBM	B-Device
7072	I-Device
,	O
and	O
IBM	B-Device
7074	I-Device
alphamerics	O
are	O
encoded	O
using	O
digit	O
pairs	O
(	O
using	O
two-out-of-five	O
code	O
in	O
the	O
digits	O
,	O
not	O
BCD	O
)	O
of	O
the	O
10-digit	O
word	O
,	O
with	O
the	O
"	O
zone	O
"	O
in	O
the	O
left	O
digit	O
and	O
the	O
"	O
digit	O
"	O
in	O
the	O
right	O
digit	O
.	O
</s>
<s>
With	O
the	O
introduction	O
of	O
System/360	B-Application
,	O
IBM	O
expanded	O
6-bit	O
BCD	O
alphamerics	O
to	O
8-bit	O
EBCDIC	B-Language
,	O
allowing	O
the	O
addition	O
of	O
many	O
more	O
characters	O
(	O
e.g.	O
,	O
lowercase	O
letters	O
)	O
.	O
</s>
<s>
A	O
variable	O
length	O
Packed	O
BCD	O
numeric	B-Algorithm
data	O
type	O
is	O
also	O
implemented	O
,	O
providing	O
machine	O
instructions	B-General_Concept
that	O
perform	O
arithmetic	O
directly	O
on	O
packed	O
decimal	B-Application
data	O
.	O
</s>
<s>
On	O
the	O
IBM	B-Device
1130	I-Device
and	O
1800	B-Device
,	O
packed	O
BCD	O
is	O
supported	O
in	O
software	O
by	O
IBM	O
's	O
Commercial	O
Subroutine	O
Package	O
.	O
</s>
<s>
Today	O
,	O
BCD	O
data	O
is	O
still	O
heavily	O
used	O
in	O
IBM	O
processors	O
and	O
databases	O
,	O
such	O
as	O
IBM	B-Application
Db2	I-Application
,	O
mainframes	O
,	O
and	O
Power6	B-Device
.	O
</s>
<s>
In	O
these	O
products	O
,	O
the	O
BCD	O
is	O
usually	O
zoned	O
BCD	O
(	O
as	O
in	O
EBCDIC	B-Language
or	O
ASCII	B-Protocol
)	O
,	O
Packed	O
BCD	O
(	O
two	O
decimal	B-Application
digits	O
per	O
byte	B-Application
)	O
,	O
or	O
"	O
pure	O
"	O
BCD	O
encoding	O
(	O
one	O
decimal	B-Application
digit	O
stored	O
as	O
BCD	O
in	O
the	O
low	O
four	O
bits	O
of	O
each	O
byte	B-Application
)	O
.	O
</s>
<s>
To	O
convert	O
packed	O
decimals	B-Application
in	O
EBCDIC	B-Language
table	O
unloads	O
to	O
readable	O
numbers	O
,	O
you	O
can	O
use	O
the	O
OUTREC	O
FIELDS	O
mask	O
of	O
the	O
JCL	O
utility	O
DFSORT	O
.	O
</s>
<s>
The	O
Digital	O
Equipment	O
Corporation	O
VAX-11	O
series	O
includes	O
instructions	B-General_Concept
that	O
can	O
perform	O
arithmetic	O
directly	O
on	O
packed	O
BCD	O
data	O
and	O
convert	O
between	O
packed	O
BCD	O
data	O
and	O
other	O
integer	O
representations	O
.	O
</s>
<s>
The	O
VAX	B-Device
's	O
packed	O
BCD	O
format	O
is	O
compatible	O
with	O
that	O
on	O
IBM	B-Application
System/360	I-Application
and	O
IBM	O
's	O
later	O
compatible	O
processors	O
.	O
</s>
<s>
The	O
MicroVAX	O
and	O
later	O
VAX	B-Device
implementations	O
dropped	O
this	O
ability	O
from	O
the	O
CPU	O
but	O
retained	O
code	O
compatibility	O
with	O
earlier	O
machines	O
by	O
implementing	O
the	O
missing	O
instructions	B-General_Concept
in	O
an	O
operating	O
system-supplied	O
software	O
library	O
.	O
</s>
<s>
This	O
is	O
invoked	O
automatically	O
via	O
exception	B-General_Concept
handling	I-General_Concept
when	O
the	O
defunct	O
instructions	B-General_Concept
are	O
encountered	O
,	O
so	O
that	O
programs	O
using	O
them	O
can	O
execute	O
without	O
modification	O
on	O
the	O
newer	O
machines	O
.	O
</s>
<s>
The	O
Intel	B-Operating_System
x86	I-Operating_System
architecture	O
supports	O
a	O
unique	O
18-digit	O
(	O
ten-byte	O
)	O
BCD	O
format	O
that	O
can	O
be	O
loaded	O
into	O
and	O
stored	O
from	O
the	O
floating	B-Algorithm
point	I-Algorithm
registers	O
,	O
from	O
where	O
computations	O
can	O
be	O
performed	O
.	O
</s>
<s>
The	O
Motorola	B-Device
68000	I-Device
series	I-Device
had	O
BCD	O
instructions	B-General_Concept
.	O
</s>
<s>
In	O
more	O
recent	O
computers	O
such	O
capabilities	O
are	O
almost	O
always	O
implemented	O
in	O
software	O
rather	O
than	O
the	O
CPU	O
's	O
instruction	B-General_Concept
set	I-General_Concept
,	O
but	O
BCD	O
numeric	B-Algorithm
data	O
are	O
still	O
extremely	O
common	O
in	O
commercial	O
and	O
financial	O
applications	O
.	O
</s>
<s>
There	O
are	O
tricks	O
for	O
implementing	O
packed	O
BCD	O
and	O
zoned	O
decimal	B-Application
add	O
–	O
or	O
–	O
subtract	O
operations	O
using	O
short	O
but	O
difficult	O
to	O
understand	O
sequences	O
of	O
word-parallel	O
logic	O
and	O
binary	O
arithmetic	O
operations	O
.	O
</s>
<s>
For	O
example	O
,	O
the	O
following	O
code	O
(	O
written	O
in	O
C	B-Language
)	O
computes	O
an	O
unsigned	B-Algorithm
8-digit	O
packed	O
BCD	O
addition	O
using	O
32-bit	O
binary	O
operations	O
:	O
</s>
<s>
BCD	O
is	O
very	O
common	O
in	O
electronic	O
systems	O
where	O
a	O
numeric	B-Algorithm
value	O
is	O
to	O
be	O
displayed	O
,	O
especially	O
in	O
systems	O
consisting	O
solely	O
of	O
digital	O
logic	O
,	O
and	O
not	O
containing	O
a	O
microprocessor	O
.	O
</s>
<s>
This	O
matches	O
much	O
more	O
closely	O
the	O
physical	O
reality	O
of	O
display	O
hardware	O
—	O
a	O
designer	O
might	O
choose	O
to	O
use	O
a	O
series	O
of	O
separate	O
identical	O
seven-segment	B-General_Concept
displays	I-General_Concept
to	O
build	O
a	O
metering	O
circuit	O
,	O
for	O
example	O
.	O
</s>
<s>
If	O
the	O
numeric	B-Algorithm
quantity	O
were	O
stored	O
and	O
manipulated	O
as	O
pure	O
binary	O
,	O
interfacing	O
with	O
such	O
a	O
display	O
would	O
require	O
complex	O
circuitry	O
.	O
</s>
<s>
10001	O
is	O
the	O
binary	O
,	O
not	O
decimal	B-Application
,	O
representation	O
of	O
the	O
desired	O
result	O
,	O
but	O
the	O
most	O
significant	O
1	O
(	O
the	O
"	O
carry	O
"	O
)	O
cannot	O
fit	O
in	O
a	O
4-bit	O
binary	O
number	O
.	O
</s>
<s>
In	O
BCD	O
as	O
in	O
decimal	B-Application
,	O
there	O
cannot	O
exist	O
a	O
value	O
greater	O
than	O
9	O
(	O
1001	O
)	O
per	O
digit	O
.	O
</s>
<s>
Some	O
CPUs	O
provide	O
a	O
half-carry	B-Device
flag	I-Device
to	O
facilitate	O
BCD	O
arithmetic	O
adjustments	O
following	O
binary	O
addition	O
and	O
subtraction	O
operations	O
.	O
</s>
<s>
The	O
Intel	B-General_Concept
8080	I-General_Concept
,	O
the	O
Zilog	B-General_Concept
Z80	I-General_Concept
and	O
the	O
CPUs	O
of	O
the	O
x86	B-Operating_System
family	O
provide	O
the	O
opcode	O
DAA	O
(	O
Decimal	B-Device
Adjust	I-Device
Accumulator	O
)	O
.	O
</s>
<s>
Subtraction	O
is	O
done	O
by	O
adding	O
the	O
ten	B-Algorithm
's	I-Algorithm
complement	I-Algorithm
of	O
the	O
subtrahend	O
to	O
the	O
minuend	O
.	O
</s>
<s>
The	O
ten	B-Algorithm
's	I-Algorithm
complement	I-Algorithm
of	O
432	O
can	O
be	O
obtained	O
by	O
taking	O
the	O
nine	B-Algorithm
's	I-Algorithm
complement	I-Algorithm
of	O
432	O
,	O
and	O
then	O
adding	O
one	O
.	O
</s>
<s>
Since	O
BCD	O
is	O
a	O
form	O
of	O
decimal	B-Application
representation	O
,	O
several	O
of	O
the	O
digit	O
sums	O
above	O
are	O
invalid	O
.	O
</s>
<s>
The	O
ten	B-Algorithm
's	I-Algorithm
complement	I-Algorithm
of	O
925	O
is	O
1000	O
−	O
925	O
=	O
75	O
,	O
so	O
the	O
calculated	O
answer	O
is	O
−75	O
.	O
</s>
<s>
If	O
there	O
are	O
a	O
different	O
number	O
of	O
nibbles	O
being	O
added	O
together	O
(	O
such	O
as	O
1053	O
−	O
2	O
)	O
,	O
the	O
number	O
with	O
the	O
fewer	O
digits	O
must	O
first	O
be	O
prefixed	O
with	O
zeros	O
before	O
taking	O
the	O
ten	B-Algorithm
's	I-Algorithm
complement	I-Algorithm
or	O
subtracting	O
.	O
</s>
<s>
So	O
,	O
with	O
1053	O
−	O
2	O
,	O
2	O
would	O
have	O
to	O
first	O
be	O
represented	O
as	O
0002	O
in	O
BCD	O
,	O
and	O
the	O
ten	B-Algorithm
's	I-Algorithm
complement	I-Algorithm
of	O
0002	O
would	O
have	O
to	O
be	O
calculated	O
.	O
</s>
<s>
Many	O
non-integral	O
values	O
,	O
such	O
as	O
decimal	B-Application
0.2	O
,	O
have	O
an	O
infinite	O
place-value	O
representation	O
in	O
binary	O
(	O
001100110011	O
...	O
)	O
but	O
have	O
a	O
finite	O
place-value	O
in	O
binary-coded	O
decimal	B-Application
(	O
0.0010	O
)	O
.	O
</s>
<s>
Consequently	O
,	O
a	O
system	O
based	O
on	O
binary-coded	O
decimal	B-Application
representations	O
of	O
decimal	B-Application
fractions	O
avoids	O
errors	O
representing	O
and	O
calculating	O
such	O
values	O
.	O
</s>
<s>
Rounding	B-Algorithm
at	O
a	O
decimal	B-Application
digit	O
boundary	O
is	O
simpler	O
.	O
</s>
<s>
Addition	O
and	O
subtraction	O
in	O
decimal	B-Application
do	O
not	O
require	O
rounding	B-Algorithm
.	O
</s>
<s>
The	O
alignment	O
of	O
two	O
decimal	B-Application
numbers	O
(	O
for	O
example	O
1.3	O
+	O
27.08	O
)	O
is	O
a	O
simple	O
,	O
exact	O
shift	O
.	O
</s>
<s>
Conversion	O
to	O
a	O
character	O
form	O
or	O
for	O
display	O
(	O
e.g.	O
,	O
to	O
a	O
text-based	O
format	O
such	O
as	O
XML	B-Protocol
,	O
or	O
to	O
drive	O
signals	O
for	O
a	O
seven-segment	B-General_Concept
display	I-General_Concept
)	O
is	O
a	O
simple	O
per-digit	O
mapping	O
,	O
and	O
can	O
be	O
done	O
in	O
linear	O
(O(n )	O
)	O
time	O
.	O
</s>
<s>
Standard	O
BCD	O
requires	O
four	O
bits	O
per	O
digit	O
,	O
roughly	O
20	O
per	O
cent	O
more	O
space	O
than	O
a	O
binary	B-Algorithm
encoding	I-Algorithm
(	O
the	O
ratio	O
of	O
4	O
bits	O
to	O
log210	O
bits	O
is	O
1.204	O
)	O
.	O
</s>
<s>
When	O
packed	O
so	O
that	O
three	O
digits	O
are	O
encoded	O
in	O
ten	O
bits	O
,	O
the	O
storage	O
overhead	O
is	O
greatly	O
reduced	O
,	O
at	O
the	O
expense	O
of	O
an	O
encoding	O
that	O
is	O
unaligned	O
with	O
the	O
8-bit	O
byte	B-Application
boundaries	O
common	O
on	O
existing	O
hardware	O
,	O
resulting	O
in	O
slower	O
implementations	O
on	O
these	O
systems	O
.	O
</s>
<s>
Programmable	B-Application
calculators	I-Application
manufactured	O
by	O
Texas	O
Instruments	O
,	O
Hewlett-Packard	O
,	O
and	O
others	O
typically	O
employ	O
a	O
floating-point	B-Algorithm
BCD	O
format	O
,	O
typically	O
with	O
two	O
or	O
three	O
digits	O
for	O
the	O
(	O
decimal	B-Application
)	O
exponent	O
.	O
</s>
<s>
The	O
extra	O
bits	O
of	O
the	O
sign	O
digit	O
may	O
be	O
used	O
to	O
indicate	O
special	O
numeric	B-Algorithm
values	O
,	O
such	O
as	O
infinity	B-Application
,	O
underflow/overflow	O
,	O
and	O
error	O
(	O
a	O
blinking	O
display	O
)	O
.	O
</s>
<s>
Signed	O
decimal	B-Application
values	O
may	O
be	O
represented	O
in	O
several	O
ways	O
.	O
</s>
<s>
The	O
COBOL	B-Application
programming	I-Application
language	I-Application
,	O
for	O
example	O
,	O
supports	O
five	O
zoned	O
decimal	B-Application
formats	O
,	O
with	O
each	O
one	O
encoding	O
the	O
numeric	B-Algorithm
sign	O
in	O
a	O
different	O
way	O
:	O
</s>
<s>
The	O
mentioned	O
3GPP	O
document	O
defines	O
TBCD-STRING	O
with	O
swapped	O
nibbles	O
in	O
each	O
byte	B-Application
.	O
</s>
<s>
If	O
errors	O
in	O
representation	O
and	O
computation	O
are	O
more	O
important	O
than	O
the	O
speed	O
of	O
conversion	O
to	O
and	O
from	O
display	O
,	O
a	O
scaled	O
binary	O
representation	O
may	O
be	O
used	O
,	O
which	O
stores	O
a	O
decimal	B-Application
number	O
as	O
a	O
binary-encoded	O
integer	O
and	O
a	O
binary-encoded	O
signed	O
decimal	B-Application
exponent	O
.	O
</s>
<s>
This	O
representation	O
allows	O
rapid	O
multiplication	O
and	O
division	O
,	O
but	O
may	O
require	O
shifting	O
by	O
a	O
power	O
of	O
10	O
during	O
addition	O
and	O
subtraction	O
to	O
align	O
the	O
decimal	B-Application
points	O
.	O
</s>
<s>
It	O
is	O
appropriate	O
for	O
applications	O
with	O
a	O
fixed	O
number	O
of	O
decimal	B-Application
places	O
that	O
do	O
not	O
then	O
require	O
this	O
adjustment	O
—	O
particularly	O
financial	O
applications	O
where	O
2	O
or	O
4	O
digits	O
after	O
the	O
decimal	B-Application
point	O
are	O
usually	O
enough	O
.	O
</s>
<s>
Indeed	O
,	O
this	O
is	O
almost	O
a	O
form	O
of	O
fixed	O
point	O
arithmetic	O
since	O
the	O
position	O
of	O
the	O
radix	B-Algorithm
point	I-Algorithm
is	O
implied	O
.	O
</s>
<s>
Densely	O
packed	O
decimal	B-Application
(	O
DPD	O
)	O
is	O
a	O
similar	O
scheme	O
that	O
is	O
used	O
for	O
most	O
of	O
the	O
significand	B-Algorithm
,	O
except	O
the	O
lead	O
digit	O
,	O
for	O
one	O
of	O
the	O
two	O
alternative	O
decimal	B-Application
encodings	O
specified	O
in	O
the	O
IEEE	O
754-2008	O
floating-point	B-Algorithm
standard	O
.	O
</s>
<s>
The	O
BIOS	B-Operating_System
in	O
many	O
personal	B-Device
computers	I-Device
stores	O
the	O
date	O
and	O
time	O
in	O
BCD	O
because	O
the	O
MC6818	B-Device
real-time	O
clock	O
chip	O
used	O
in	O
the	O
original	O
IBM	B-Operating_System
PC	I-Operating_System
AT	I-Operating_System
motherboard	O
provided	O
the	O
time	O
encoded	O
in	O
BCD	O
.	O
</s>
<s>
This	O
form	O
is	O
easily	O
converted	O
into	O
ASCII	B-Protocol
for	O
display	O
.	O
</s>
<s>
The	O
Atari	B-Device
8-bit	I-Device
family	I-Device
of	O
computers	O
used	O
BCD	O
to	O
implement	O
floating-point	B-Algorithm
algorithms	O
.	O
</s>
<s>
The	O
MOS	B-General_Concept
6502	I-General_Concept
processor	O
has	O
a	O
BCD	O
mode	O
that	O
affects	O
the	O
addition	O
and	O
subtraction	O
instructions	B-General_Concept
.	O
</s>
<s>
The	O
Psion	B-Application
Organiser	I-Application
1	I-Application
handheld	O
computer	O
's	O
manufacturer-supplied	O
software	O
also	O
entirely	O
used	O
BCD	O
to	O
implement	O
floating	B-Algorithm
point	I-Algorithm
;	O
later	O
Psion	O
models	O
used	O
binary	O
exclusively	O
.	O
</s>
<s>
Early	O
models	O
of	O
the	O
PlayStation	B-Operating_System
3	I-Operating_System
store	O
the	O
date	O
and	O
time	O
in	O
BCD	O
.	O
</s>
