{"id":19087,"date":"2021-08-29T15:13:26","date_gmt":"2021-08-29T09:43:26","guid":{"rendered":"https:\/\/python-programs.com\/?p=19087"},"modified":"2021-11-22T18:37:09","modified_gmt":"2021-11-22T13:07:09","slug":"python-program-to-convert-binary-to-decimal-using-recursion","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-convert-binary-to-decimal-using-recursion\/","title":{"rendered":"Python Program to Convert Binary to Decimal using Recursion"},"content":{"rendered":"

In the previous article, we have discussed Python Program for Sign Change<\/a>
\nRecursion:<\/strong><\/p>\n

Recursion is the process by which a function calls itself directly or indirectly, and the associated function is known as a recursive function. Certain issues can be addressed fairly easily using a recursive approach. Towers of Hanoi (TOH), Inorder \/Preorder\/Postorder Tree Traversals, DFS of Graph, and other analogous issues are examples.<\/p>\n

Binary Code:<\/strong><\/p>\n

As previously stated, Binary Code is a Base-2 representation of a number. In Binary, all numbers are represented by simply two symbols: 0 and 1. Binary (also known as base-2) is a numerical system with only two digits: 0 and 1.<\/p>\n

Given a binary string, the task is to convert the given binary string to a decimal number using recursion in Python.<\/p>\n

Examples:<\/strong><\/p>\n

Example1:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Given binary number = 1011<\/pre>\n

Output:<\/strong><\/p>\n

The decimal Equivalent of the given binary number { 1011 } is : 11<\/pre>\n

Example2:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Given binary number = 10010101<\/pre>\n

Output:<\/strong><\/p>\n

The decimal Equivalent of the given binary number { 10010101 } is : 149<\/pre>\n

Program to Convert Binary to Decimal using Recursion in Python<\/h2>\n

Below are the ways to convert the given binary string to a decimal number using recursion in Python:<\/p>\n