The Wayback Machine - https://web.archive.org/web/20241004133954/https://www.geeksforgeeks.org/bcd-or-binary-coded-decimal/
Open In App

BCD or Binary Coded Decimal

Last Updated : 13 Dec, 2023
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

Binary Coded Decimal, or BCD, is another process for converting decimal numbers into their binary equivalents. 
 

  • It is a form of binary encoding where each digit in a decimal number is represented in the form of bits.
  • This encoding can be done in either 4-bit or 8-bit (usually 4-bit is preferred).
  • It is a fast and efficient system that converts the decimal numbers into binary numbers as compared to the existing binary system.
  • These are generally used in digital displays where is the manipulation of data is quite a task.
  • Thus BCD plays an important role here because the manipulation is done treating each digit as a separate single sub-circuit.

The BCD equivalent of a decimal number is written by replacing each decimal digit in the integer and fractional parts with its four bit binary equivalent.the BCD code is more precisely known as 8421 BCD code  , with 8,4,2 and 1 representing the weights of different bits in the four-bit groups, Starting from MSB and proceeding towards LSB. This feature makes it a weighted code , which means that each bit in the four bit group representing a given decimal digit has an assigned weight.
Many decimal values, have an infinite place-value representation in binary but have a finite place-value in binary-coded decimal. For example, 0.2 in binary is .001100… and in BCD is 0.0010. It avoids fractional errors and is also used in huge financial calculations. 

Consider the following truth table and focus on how are these represented. 

Truth Table for Binary Coded Decimal 
 

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

In the BCD numbering system, the given decimal number is segregated into chunks of four bits for each decimal digit within the number. Each decimal digit is converted into its direct binary form (usually represented in 4-bits). 

For example: 
 

1. Convert (123)10 in BCD 

From the truth table above, 
1 -> 0001 
2 -> 0010 
3 -> 0011 
thus, BCD becomes -> 0001 0010 0011 
 

 

2. Convert (324)10 in BCD 

(324)10 -> 0011 0010 0100 (BCD) 

Again from the truth table above, 
3 -> 0011 
2 -> 0010 
4 -> 0100 
thus, BCD becomes -> 0011 0010 0100 
 

This is how decimal numbers are converted to their equivalent BCDs. 
 

  • It is noticeable that the BCD is nothing more than a binary representation of each digit of a decimal number.
  • It cannot be ignored that the BCD representation of the given decimal number uses extra bits, which makes it heavy-weighted.

Related articles: 
 

  1. Program to Convert BCD number into Decimal number 
     
  2. BCD Adder in Digital Logic 
     
  3. BCD to 7 Segment Decoder

 


Previous Article
Next Article

Similar Reads

Program to convert Hexa-Decimal Number to its equivalent BCD
Given a HexaDecimal Number N, the task is to convert the number to its equivalent Binary Coded Decimal.Examples: Input: 11F Output: 0001 0001 1111 Explanation: Binary of 1 - 0001 Binary of F - 1111 Thus, Equivalent BCD is 0001 0001 1111Input: A D Output: 1010 1101 Explanation: Binary of A - 1010 Binary of D - 1101 Thus, Equivalent BCD is 1010 1101
10 min read
Program to Convert BCD number into Decimal number
Given a BCD (Binary Coded Decimal) number, the task is to convert the BCD number into its equivalent Decimal number. Examples: Input: BCD = 100000101000 Output: 828 Explanation: Dividing the number into chunks of 4, it becomes 1000 0010 1000. Here, 1000 is equivalent to 8 and 0010 is equivalent to 2. So, the number becomes 828. Input: BCD = 1001000
10 min read
BCD addition of given Decimal numbers
Given two numbers A and B, the task is to perform BCD Addition of the given numbers. Examples: Input: A = 12, B = 20 Output: 110010 Explanation: The summation of A and B is 12 + 20 = 32. The binary representation of 3 = 0011 The binary representation of 2 = 0010 Therefore, the BCD Addition is "0011" + "0010" = "110010" Input: A = 10, B = 10 Output:
5 min read
Convert a given Decimal number to its BCD representation
Given a decimal number N, the task is to convert N to it's Binary Coded Decimal(BCD) form.Examples: Input: N = 12 Output: 0001 0010 Explanation: Considering 4-bit concept: 1 in binary is 0001 and 2 in binary is 0010. So it's equivalent BCD is 0001 0010. Input: N = 10 Output: 0001 0000 Explanation: Considering 4-bit concept: 1 in binary is 0001 and
5 min read
Convert the given BCD to its equivalent Binary form
Given a BCD (Binary Coded Decimal), the task is to convert this to its equivalent Binary number. Examples: Input: 1001000 Output: 110000 Explanation: Integer value of the given BCD is 48(0100 -> 4, 1000 -> 8). (48)10 = (110000)2 Input: 1001001 Output: 110000 Approach: In order to solve this problem we need to split the given BCD number into b
6 min read
Sum of decimal equivalents of binary node values in each level of a Binary Tree
Given a Binary Tree consisting of nodes with values 0 and 1 only, the task is to find the total sum of the decimal equivalents of the binary numbers formed by connecting nodes at the same level from left to right, on each level. Examples: Input: Below is the given Tree: 0 / \ 1 0 / \ / \ 0 1 1 1Output: 9Explanation: Binary number formed at level 1
15 min read
Number of substrings with odd decimal value in a binary string
Given a binary string containing only 0's and 1's. Write a program to find number of sub-strings of this string whose decimal representation is odd. Examples : Input : 101 Output : 3 Explanation : Substrings with odd decimal representation are: {1, 1, 101} Input : 1101 Output : 6 Explanation : Substrings with odd decimal representation are: {1, 1,
6 min read
Decimal representation of given binary string is divisible by 20 or not
The problem is to check whether the decimal representation of the given binary number is divisible by 20 or not. Take care, the number could be very large and may not fit even in long long int. The approach should be such that there are zero or the minimum numbers of multiplication and division operations. No leadings 0’s are there in the input. Ex
14 min read
Sum of decimal equivalent of all possible pairs of Binary representation of a Number
Given a number N. The task is to find the sum of the decimal equivalent of all the pairs formed from the binary representation of the given number. Examples: Input: N = 4 Output: 4 Binary equivalent of 4 is 100. All possible pairs are 10, 10, 00 and their decimal equivalent are 2, 2, 0 respectively. So, 2 + 2+ 0 = 4 Input: N = 11 Output: 13 All pos
5 min read
Decimal to Binary using recursion and without using power operator
Given an integer N, the task is convert and print the binary equaiva;ent of N.Examples: Input: N = 13 Output: 1101Input: N = 15 Output: 1111 Approach Write a recursive function that takes an argument N and recursively calls itself with the value N / 2 as the new argument and prints N % 2 after the call. The base condition will be when N = 0, simply
3 min read
Maximum decimal equivalent possible among all connected components of a Binary Valued Graph
Given a binary-valued Undirected Graph with V vertices and E edges, the task is to find the maximum decimal equivalent among all the connected components of the graph. A binary-valued graph can be considered as having only binary numbers (0 or 1) as the vertex values. Examples: Input: E = 4, V = 7 Output: 3 Explanation: Decimal equivalents of the c
14 min read
Check if decimal representation of Binary String is divisible by 9 or not
Given a binary string S of length N, the task is to check if the decimal representation of the binary string is divisible by 9 or not. Examples: Input: S = 1010001Output:YesExplanation: The decimal representation of the binary string S is 81, which is divisible by 9. Therefore, the required output is Yes. Input: S = 1010011Output: NoExplanation: Th
12 min read
Rearrange array to make decimal equivalents of reversed binary representations of array elements sorted
Given an array arr[] consisting of N positive integers, the task is to rearrange the array such that the reversed binary representation of all the array elements is sorted. If the decimal equivalent of reversed binary representations of two or more array elements is equal, then the original value is taken into consideration while rearranging the ar
13 min read
Check if level-wise Decimal equivalent of Binary Tree forms a Monotonic sequence or not
Given the root of a binary tree in which all nodes has values either 0 or 1, the task is to check if the level-wise decimal equivalent of given Tree forms a monotonic sequence.or not. A sequence is monotonic if it is either monotone increasing or monotone decreasing. A sequence nums is monotone increasing if for all i <= j, nums[i] <= nums[j]
15+ min read
Program to convert a Binary Number to Hexa-Decimal Number
Given a Binary Number, the task is to convert this Binary number to its equivalent Hexa-Decimal Number.Examples: Input: 100000101111 Output: 82F Explanation: Dividing the number into chunks of 4, it becomes 1000 0010 1111. Here, 1000 is equivalent to 8, 0010 is equivalent to 2 and 1111 is equivalent to F Therefore, the number becomes 82FInput:10101
10 min read
Convert Binary to Decimal in Swift
In computers, we use two main number systems: binary (with 0s and 1s) and decimal (with numbers from 0 to 9). Converting binary numbers (like 1010) into decimal numbers (like 10) is a common task in programming. In this article, we'll learn how to do this in Swift, a programming language developed by Apple. Problem StatementThe problem is to conver
2 min read
Counting even decimal value substrings in a binary string
Given a binary string of size N. Count all substring that have even decimal value considering binary to decimal conversion from left to right (For example a substring "1011" is treated as 13) Examples : Input : 101Output : 2Explanation : Substring are : 1, 10, 101, 0, 01, 1 In decimal form : 1, 1, 3, 0, 2, 1 There are only 2 even decimal value subs
9 min read
Decimal Equivalent of Binary Linked List
Given a singly linked list of 0s and 1s find its decimal equivalent. Input : 0->0->0->1->1->0->0->1->0 Output : 50 Input : 1->0->0 Output : 4The decimal value of an empty linked list is considered as 0. Recommended PracticeDecimal Equivalent of Binary Linked ListTry It!Initialize the result as 0. Traverse the linked li
10 min read
Maximum decimal value path in a binary matrix
Given binary square matrix [n*n]. Find maximum integer value in a path from top left to bottom right. We compute integer value using bits of traversed path. We start at index [0,0] and end at index [n-1][n-1]. from index [i, j], we can move [i, j+1] or [i+1, j]. Examples: Input : mat[][] = {{1, 1, 0, 1}, {0, 1, 1, 0}, {1, 0, 0, 1}, {1, 0, 1, 1}} Ou
14 min read
Convert Binary fraction to Decimal
Given an string of binary number n. Convert binary fractional n into it's decimal equivalent. Examples: Input: n = 110.101 Output: 6.625 Input: n = 101.1101 Output: 5.8125We strongly recommend that you click here and practice it, before moving on to the solution. Following are the steps of converting binary fractional to decimal. A) Convert the int
6 min read
Queries for decimal values of subarrays of a binary array
Given a binary array arr[], we to find the number represented by the subarray a[l..r]. There are multiple such queries. Examples: Input : arr[] = {1, 0, 1, 0, 1, 1}; l = 2, r = 4 l = 4, r = 5 Output : 5 3 Subarray 2 to 4 is 101 which is 5 in decimal. Subarray 4 to 5 is 11 which is 3 in decimal. Input : arr[] = {1, 1, 1} l = 0, r = 2 l = 1, r = 2 Ou
11 min read
Binary to decimal and vice-versa in python
Write Python code for converting a decimal number to it's binary equivalent and vice-versa. Example: From decimal to binary Input : 8 Output : 1 0 0 0 From binary to decimal Input : 100 Output : 4 Decimal to binary Keep calling conversion function with n/2 till n > 1, later perform n % 1 to get MSB of converted binary number. Example :- 7 1). 7/
4 min read
Decimal to binary conversion without using arithmetic operators
Find the binary equivalent of the given non-negative number n without using arithmetic operators. Examples: Input : n = 10Output : 1010 Input : n = 38Output : 100110 Note that + in below algorithm/program is used for concatenation purpose. Algorithm: decToBin(n) if n == 0 return "0" Declare bin = "" Declare ch while n > 0 if (n & 1) == 0 ch
8 min read
Decimal representation of given binary string is divisible by 10 or not
The problem is to check whether the decimal representation of the given binary number is divisible by 10 or not. Take care, the number could be very large and may not fit even in long long int. The approach should be such that there are zero or minimum number of multiplication and division operations. No leading 0’s are there in the input.Examples:
14 min read
Convert decimal fraction to binary number
Given a fraction decimal number n and integer k, convert decimal number n into equivalent binary number up-to k precision after decimal point. Examples: Input: n = 2.47, k = 5 Output: 10.01111 Input: n = 6.986 k = 8 Output: 110.11111100We strongly recommend that you click here and practice it, before moving on to the solution. A) Convert the integr
9 min read
Decimal to binary number using recursion
Given a decimal number as input, we need to write a program to convert the given decimal number into an equivalent binary number.  Examples :  Input : 7 Output :111 Input :10 Output :1010 We have discussed one iterative solution in below post. Program for Decimal to Binary ConversionBelow is Recursive solution: findBinary(decimal) if (decimal == 0)
6 min read
Program for Binary To Decimal Conversion
Given a binary number as input, we need to write a program to convert the given binary number into an equivalent decimal number. Check: Binary to Decimal ConverterExamples :  Input : 111Output : 7Input : 1010Output : 10Input: 100001Output: 33Recommended PracticeBinary number to decimal numberTry It!The idea is to extract the digits of a given binar
15+ min read
Decimal representation of given binary string is divisible by 5 or not
The problem is to check whether the decimal representation of the given binary number is divisible by 5 or not. Take care, the number could be very large and may not fit even in long long int. The approach should be such that there are zero or minimum number of multiplication and division operations. No leading 0's are there in the input. Examples:
12 min read
Program for Decimal to Binary Conversion
Given a decimal number as input, we need to write a program to convert the given decimal number into an equivalent binary number. Examples of Decimal to Binary:  Input : 7Output : 111Input : 10Output : 1010Input: 33Output: 100001Recommended PracticeDecimal to binaryTry It!Brute force ApproachFor Example: If the decimal number is 10. Step 1: Remaind
15+ min read
Javascript Program To Find Decimal Equivalent Of Binary Linked List
Given a singly linked list of 0s and 1s find its decimal equivalent. Input: 0->0->0->1->1->0->0->1->0Output: 50 Input: 1->0->0Output: 4The decimal value of an empty linked list is considered as 0. Initialize the result as 0. Traverse the linked list and for each node, multiply the result by 2 and add the node's data to
3 min read