# Binary to decimal program

#### binary to decimal in c

``` #include<stdio.h> #include<conio.h> void main() { int binaryNumber,decimalNumber=0,reminder,base=1; printf("Enter the binary number \n"); scanf("%d",&binaryNumber); for(int i=0;binaryNumber>0;i++) { reminder=binaryNumber%10; binaryNumber/=10; if(reminder==1) { decimalNumber+=base; } base*=2; } printf("Its equivalent decimal number is = %d",decimalNumber); getch(); } ```

#### Output

```Enter the binary number 101 Its equivalent decimal number is = 5 ```

#### binary to decimal in c++

``` #include<iostream> #include<conio.h> using namespace std; void main() { int binaryNumber,decimalNumber=0,reminder,base=1; cout<<"Enter the binary number \n"; cin>>binaryNumber; for(int i=0;binaryNumber>0;i++) { reminder=binaryNumber%10; binaryNumber/=10; if(reminder==1) { decimalNumber+=base; } base*=2; } cout<<"Its equivalent decimal number is = "<<decimalNumber; getch(); } ```

#### Output

```Enter the binary number 111 Its equivalent decimal number is = 7 ```

#### binary to decimal in c#

``` using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConvertBinaryToDecimal { class Program { static void Main(string[] args) { int binaryNumber, decimalNumber=0, baseNumber = 1,reminder; Console.WriteLine("Enter the binary number"); binaryNumber = Convert.ToInt32(Console.ReadLine()); for (int i = 0; binaryNumber > 0; i++) { reminder = binaryNumber % 10; binaryNumber /= 10; if (reminder == 1) { decimalNumber += baseNumber; } baseNumber *= 2; } Console.WriteLine("Its equivalent decimal number is = " + decimalNumber); Console.ReadLine(); } } } ```

#### Output

```Enter the binary number 1001 Its equivalent decimal number is = 9 ```

#### binary to decimal in java

``` import java.util.*; class examples { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int binaryNumber, decimalNumber=0, baseNumber = 1,reminder; System.out.println("Enter the binary number"); binaryNumber = sc.nextInt(); for (int i = 0; binaryNumber > 0; i++) { reminder = binaryNumber % 10; binaryNumber /= 10; if (reminder == 1) { decimalNumber += baseNumber; } baseNumber *= 2; } System.out.println("Its equivalent decimal number is = " + decimalNumber); } } ```

#### Output

```Enter the binary number 1011 Its equivalent decimal number is = 11 ```

### Write a comment

Name Email Message