# Decimal Coded Binary (BCD) Tutorial

Decimal Coded Binary (BCD) Explanation With Examples - When we learn electronic programming, we will use various number formats.

In computer number format, there are 4 of the most famous of number, like Binary, Decimal, Octal and Hexadecimal.

Binary numbers are numbers that consist of two values, is 0 and 1, for example 0000, 0011, 0110 and so on.

Representatives of one value in binary numbers are called bit. For example, the binary value 0010 is called 4 bits or 10010110 is called 8 bits. 8 bits are also called 1 byte.

Decimal numbers are numbers that use the numbers 0, 1, 2, 3, 4, 5, 6, 7, 8, 9. These numbers are often referred to as base-10 numbers, because they use 10 numbers.

Octal numbers are numbers that use the numbers 0, 1, 2, 3, 4, 5, 6, 7. These numbers are often referred to as base 8 numbers.

Hexadecimal numbers are numbers that use numbers and letters 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, A, B, C, D, E, and F. with base 15 numbers.

There is one more number that is often used in microcontroller programming, namely Binary Coded Decimal (BCD).

## What is BCD Mean?

Decimal Coded Binary is a binary number that follows a decimal number limit with a value range from 0 (0000) to 9 (1001).

In contrast to the hexadecimal value which has range from 0 (0000) to 15 or F (1111).

BCD code, using a 4-bit binary code from 0000 to 1001.So the binary value are:

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

If we want to represent the number 15 into BCD. 15 if written in the correct BCD code is:

0001 0101 (BCD)

If we want to present the number 39 into BCD. 39 if written in the correct BCD code is:

0011 1001 (BCD)

And if we want to represent the number 939 into BCD. 939 if written in the correct BCD code is:

1001 0011 1001 (BCD)

Then what are the advantages using Binary Coded Decimal? the advantage is makes converting decimal values ​​to binary easier.

So what are the disadvantages of using this Binary Coded Decimal? The disadvantage is that there is empty space in binary that is not used, above a value of 9 (1001) such as 10 (1010) to 15 (1111).

## Binary Code Decimal Conversion

### 1. How to Convert BCD to Decimal in Arduino Programming

In some microcontroller projects, sometimes we have to convert this BCD value to a Decimal value. As in the case example, reading the value or time data from the RTC without using a third party library such as Adafruit's RTClib library.

The way to convert it is to use the following program line:

### 2. How to Convert Decimal to BCD In Arduino programming

As for the Decimal to BCD are as follows:

Hope it is useful.

Source: Arduino32