saving . . . saved please help me with this has been deleted. please help me with this has been hidden .
please help me with this
Title
Question
<pre>(a) Given a binary number, find out its decimal equivalent Eg. 11010 => 26 </pre>

Java do-while 06-07 min 50-60 sec 26-05-21, 10:42 a.m. kronoz_z1

Answers:

Hi Kronoz, This is an assignment for you to solve after learning the "do while" tutorial in the "Java" - Spoken Tutorial series.
Kindly try to solve the same by yourself.

 
26-05-21, 11:33 a.m. pravin1389


import java.util.Scanner;
public class binarytodecimal {
 public static void main(String[] args)
 {
  Scanner sc = new Scanner(System.in);
  long binaryNumber, decimalNumber = 0, j = 1, remainder;
  System.out.print("Input a binary number: ");
  binaryNumber = sc.nextLong();

  while (binaryNumber != 0)
  {
   remainder = binaryNumber % 10;
   decimalNumber = decimalNumber + remainder * j;
   j = j * 2;
   binaryNumber = binaryNumber / 10;
  }
  System.out.println("Decimal Number: " + decimalNumber);
 }
}
06-12-21, 9:10 p.m. Harish1605


Log-in to answer to this question.