Computer Science, asked by jAnanyachowdhary1, 1 year ago

convert the binary number 01100011 into decimal number

Answers

Answered by adityavarman
0
Greetings,
The answer to your question is typed below ^
_____________________________________________________________

Note :The programs below are written in java programming language.

There are two ways to convert a binary number to a decimal number.
i) Using Integer.parseInt();
ii)The manual method.

I'll show you both the programs:-

i) Using Integer.parseInt(); :

import java.util.Scanner;
class bin
{ static Scanner sc=new Scanner(System.in);
public static void main(String arf[])
{
System.out.println("Enter a binary number:");
String n=s.nextLine();
System.out.println(Integer.parseInt(n,2));
}
}

ii) Using the manual method:

import java.util.Scanner;
class bin
{
static Scanner fish=new Scanner(System.in);
static int num, dec, p=0;
void bintodec(){
System.out.println("Enter a binary number");
num=fish.nextInt();
while(num!=0 )
{
dec+= (( num % 10) * Math.pow (2,p));
num = num / 10;
p++;
}
System.out.println(dec);
}
public static void main(String args[])
{
bin b=new bin();
b.bintodec();
}
}
____________________________________________________________

PS: Enjoy ;)


adityavarman: Program is written using java.
Similar questions