Given a BCD (Binary Coded Decimal) number, the task is to convert the BCD number into it’s equivalent Decimal number.
Input: BCD = 100000101000
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
Dividing the number into chunks of 4, it becomes 0100 1000.
Here, 0100 is equivalent to 4 and
1000 is equivalent to 8.
So, the number becomes 48.
- Iterate over all bits in given BCD numbers.
- Divide the given BCD number into chunks of 4, and start computing its equivalent Decimal number.
- Store this number formed in a variable named sum.
- Start framing a number from the digits stored in sum in a variable num.
- Reverse the number formed so far and return that number.
Below is the implementation of the above approach.
Time complexity: O(N)
Auxiliary Space complexity: O(1)
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Program to convert a BCD to Hexa-Decimal Number
- Program to convert Hexa-Decimal Number to its equivalent BCD
- Python program to convert decimal to binary number
- Convert a given Decimal number to its BCD representation
- Convert decimal fraction to binary number
- Convert given Decimal number into an irreducible Fraction
- Program to Convert Octal Number to Binary Number
- Program to convert Number in characters
- Program to convert a given number to words
- Program to convert a given number to words | Set 2
- Program to Convert Hexadecimal Number to Binary
- Count number of digits after decimal on dividing a number
- Convert Decimal To Hexa-Decimal including negative numbers
- Convert a binary number to hexadecimal number
- Convert a number m to n using minimum number of given operations
- 9's complement of a decimal number
- 10's Complement of a decimal number
- Decimal to binary number using recursion
- Exponential notation of a decimal number
- Number of substrings with odd decimal value in a binary string
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.