12 comments:

  1. import java.util.Scanner;

    class Test{

    public static void main(String ar[])
    {

    Scanner sc=new Scanner(System.in);
    long num,decimal_num,remainder,base=1,binary=0,noof1s=0;
    System.out.println("Enter Number to convert to Binary");
    num=sc.nextLong();
    decimal_num=num;
    while (num > 0)
    {

    remainder=num%2;
    if (remainder == 1)
    {
    noof1s++;
    }
    binary=binary+remainder*base;
    num=num/2;
    base=base*10;
    }
    System.out.println("Input number is = "+decimal_num);
    System.out.println("Its binary equivalent is = "+binary);
    System.out.println("No.of 1's in the binary number is = "+noof1s);


    }
    }

    ReplyDelete
  2. import java.util.Scanner;
    class DecTobin
    {
    public static void main(String ar[])
    {
    int t=1;
    int Total=0;
    Scanner scan=new Scanner(System.in);
    System.out.println("Enter thee Decimal number");
    int Number=scan.nextInt();
    int Number1=Number;

    while(Number>0)
    {
    Total=Total+(Number%2)*t;
    t=t*10;
    Number=Number/2;
    }
    System.out.println("Decimal to binary of"+Number1+"="+Total);

    }
    }

    ReplyDelete
  3. class Test
    {

    public static void main(String ar[])
    {
    double decimal_no;
    int number1,binary_no=0,t=1;
    System.out.print("Enter the decimal number: ");
    Scanner o= new Scanner(System.in);
    decimal_no=o.nextDouble();
    number1=(int)decimal_no;
    while(number1!=0)
    {
    binary_no=binary_no+(number1%2*t);
    number1=number1/2;
    t*=10;
    }




    System.out.println("The binary number is: "+binary_no);

    }
    }

    ReplyDelete
  4. import java.util.Scanner;
    class Binary
    {
    public static void main(String Args[])
    {
    System.out.println("enter the number");
    Scanner sc=new Scanner(System.in);
    int num;
    int t=1;
    int total=0;
    num=sc.nextInt();
    while(num>0)
    {
    total=total+(num%2)*t;
    t=t*10;
    num=num/2;
    }
    System.out.println("binary value="+total);
    }
    }


    ReplyDelete
  5. 8
    8
    8.
    8.
    8.
    8. import java.util.Scanner;
    class A
    {
    public static void main(String args[])
    {
    Scanner obj=new Scanner(System.in);
    int num;
    num=obj.nextInt();
    int i=0;
    int arr[]=new int[];
    while(num>0)
    {
    arr[i]=num%2;
    num=num/2;
    i++;
    }
    for(i=i-1;i>=0;i--)
    {
    System.out.println("The equivalent binary number is="+arr[i]);
    }
    }
    }

    ReplyDelete
  6. import java.util.Scanner;
    class Dec{
    public static void main(String ar[]){
    Scanner obj=new Scanner(System.in);
    int num,rem,bin=0,base=1;
    System.out.println("enter the value of number");
    num=obj.nextInt();

    while(num>0){
    rem=num%2;
    bin=bin+rem*base;
    num=num/2;
    base=base*10;
    }
    System.out.print(bin);

    }

    }

    ReplyDelete
  7. import java.util.Scanner;

    class Dtob{

    public static void main(String ar[]){
    int temp=1,binary=0;
    int number;

    Scanner scan=new Scanner(System.in);
    System.out.println("Enter a decimal number:");
    number=scan.nextInt();

    while(number>0){
    binary=binary+(number%2)*temp;
    temp=temp*10;
    number=number/2;
    }
    System.out.println("The binary number:"+binary);
    }
    }

    ReplyDelete
  8. import java.util.Scanner;
    class Binary{
    public static void main(String ar[]){
    int number,digit=0,reverse=0,temp=1;
    Scanner scan=new Scanner(System.in);
    System.out.println("Enter the number");
    number=scan.nextInt();

    while(number>0){
    digit=number%2;
    reverse=reverse+(digit*temp);
    temp=temp*10;
    number=number/2;


    }
    System.out.println("number="+reverse);
    }
    }

    ReplyDelete
  9. import java.util.Scanner;
    class Binary{
    public static void main(String[]ar){
    Scanner s=new Scanner(System.in);
    int d,b=0,temp=1;
    System.out.println("enter the decimal number: ");
    d=s.nextInt();
    while(d>0)
    { b=b+(d%2)*temp;
    temp=10*temp;
    d=d/2;
    }
    System.out.println("binary: "+b);
    }
    }

    ReplyDelete
  10. This comment has been removed by the author.

    ReplyDelete
  11. This comment has been removed by the author.

    ReplyDelete
  12. import java.util.Scanner;

    class Decimal{

    public static void main(String ar[]){

    Scanner scan=new Scanner(System.in);
    int decimal,rem,binary=0,temp=1;
    System.out.println("Enter Decial no.");
    decimal=scan.nextInt();
    while(decimal>0){

    rem=decimal%2;
    binary=binary+rem*temp;
    temp=10*temp;
    decimal=decimal/2;

    }
    System.out.println("Binary no.="+binary);


    }

    }

    ReplyDelete