Sunday, October 12, 2025
Latest:
  • German Pronouns with Nominative, Accusative, and Dative cases
  • German articles for the nominative, accusative, and dative cases
  • Der kleine Vogel und die Sonne
  • German alphabet pronunciation
  • Command design pattern
Upokary

Upokary

Quality information

  • Health
  • Life
  • Fashion
  • Food
  • Code
  • English
  • বাংলা
Technology 

Write a program to convert a binary number to decimal number using recursion

Published: November 7, 2022Last updated: December 26, 2022 binary, code, decimal, recursion

Converting binary numbers to decimal numbers is a little tricky. The base of binary numbers is 2. The following code segment converts a binary number to a string.

(function(){
    // Write a program to convert a binary number to a decimal number using recursion

    const getDecimal = (n) => {
        if (!n) {
            return 0;
        } 
        return  n[0] * (2 ** (n.length - 1)) + getDecimal(n.slice(1))
    };
 
    console.log(getDecimal('111')) // 7
})();

You May Also Like

How to check if string contains a substring in JavaScript?

August 6, 2021 beroza

Useful Linux networking commands

December 3, 2018 beroza

Find total number of Sundays, Saturdays between two dates in JavaScript

December 22, 2018 beroza

What is GraphQL? How to use GraphQL?

March 29, 2022 beroza

npm ERR! code ELIFECYCLE or Error: Could not locate the bindings file

September 6, 2018 beroza

What are the steps to run a ruby and rails project after cloning from Github?

May 21, 2020 beroza

What is useRef in React? What are the use cases of useRef?

August 14, 2021 beroza

Permission denied for database “postgres”, User does not have CONNECT privilege.

June 1, 2020 beroza

How to install or setup WordPress multisite?

December 4, 2019 beroza

Why Upokary?

Upokary.com is a useful application in everyday life. It provides very handy information regarding every aspect of life. Each and every tip of upokary.com is meant to make life better.

Upokary tools

  • Youtube thumbnail
  • Youtube video downloader

Useful Links

  • Handy code
  • Technology
  • People
  • Programming
  • Quote
  • Travel
  • WordPress
  • IELTS
  • Kids

Pages

  • Sitemap
  • Privacy policy
  • About us
  • Contact us

Support

For any kind of query or question please drop a message in the following email: upokary@gmail.com
Copyright © 2025 Upokary. All rights reserved.