can anyone teach me about converting decimal numbers in to binary numbers
Answers
Answered by
1
I can teach you
.. for example take 45 *10
45÷2
.. for example take 45 *10
45÷2
aakash11k:
then it would be 00110100 00110101
Answered by
0
in java i can help
here it is:
import java.util.Scanner;
public class Convert
{
public static void main(String[] args)
{
int n, count = 0, a; String x = "";
Scanner s = new Scanner(System.in);
System.out.print("Enter any decimal number:");
n = s.nextInt();
while(n > 0)
{
a = n % 2;
if(a == 1)
{
count++;
}
x = x + "" + a;
n = n / 2;
}
System.out.println("Binary number:"+x);
System.out.println("No. of 1s:"+count);
}
}
here it is:
import java.util.Scanner;
public class Convert
{
public static void main(String[] args)
{
int n, count = 0, a; String x = "";
Scanner s = new Scanner(System.in);
System.out.print("Enter any decimal number:");
n = s.nextInt();
while(n > 0)
{
a = n % 2;
if(a == 1)
{
count++;
}
x = x + "" + a;
n = n / 2;
}
System.out.println("Binary number:"+x);
System.out.println("No. of 1s:"+count);
}
}
Similar questions