Saturday, October 25, 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 mock different hooks in ReactJS?

April 25, 2021 beroza

In JavaScript what are the differences between JSON and JSONP for cross domain?

February 28, 2020 beroza

How to get URL query parameter value from query string in ReactJS?

February 24, 2020 beroza

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

September 6, 2018 beroza

ERROR: Permission to repository.git denied to username. fatal: The remote end hung up unexpectedly

August 31, 2019 beroza

Interfaces vs Types alias in TypeScript

November 10, 2021 beroza

Number of Different Integers in a String

January 3, 2023 beroza

could not connect to server: No such file or directory Is the server running locally and accepting connections on Unix domain socket

October 11, 2020 beroza

Write a Program to Find Maximum Population Year

May 11, 2023 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.