## Definition

Binary-coded decimal is a format for representing decimal numbers (integers) in which each digit is represented by four bits.

## Overview

To encode a decimal number using the common BCD encoding, each decimal digit is stored in a 4-bit nibble:

```Decimal:    0     1     2     3     4     5     6     7     8     9
BCD:     0000  0001  0010  0011  0100  0101  0110  0111  1000  1001
```

Thus, the BCD encoding for the number 127 would be:

``` 0001 0010 0111
```

Whereas the pure binary number would be:

``` 0111 1111
```

Since most computers store data in 8-bit bytes, there are two common ways of storing 4-bit BCD digits in those bytes:

Unlike binary-encoded numbers, BCD-encoded numbers can easily be displayed by mapping each of the nibbles to a different character. Converting a binary-encoded number to decimal for display is much harder, as this generally involves integer multiplication or divide operations. BCD also avoids problems where fractions that can be represented exactly in decimal cannot be represented in binary (e.g., one-tenth).

 This page uses Creative Commons Licensed content from Wikipedia (view authors). 