# 37+ Java Decimal to Binary Converter Examples

This post contains a total of 37+ Java Decimal to Binary Converter Examples with Source Code. All these Decimal to Binary Converters are made using Java Programming language.

You can use the source code of these examples with credits to the original owner.

## Java Decimal to Binary Converter Examples

### 1. By hardul Birje

Made by hardul Birje. Simple Java Program to Convert a Decimal number to Binary. Source

```Your Input: 1
Binary: 1```
``````
import java.util.*;
public class Program
{
public static void main(String[] args) {
Scanner myVar=new Scanner(System.in);
int index=0;
int i;
int input=myVar.nextInt();
int temp=input;
int []arr= new int[50];
while(temp!=1)
{
arr[index]=temp%2;
++index;
temp=temp/2;
}
System.out.print("Binary: ");
System.out.print(temp);
for (i=index-1;i>=0;i--)
{
System.out.print(arr[i]);
}

}

}``````

### 2. By Dev

Made by Dev. An easy way to convert any decimal to Binary, Octal or Hexadecimal. Source

```2 in Binary: 10
2 in Octal: 2
2 in Hex: 2```
``````import java.util.Scanner;
public class DecimalConversion
{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
if(scanner.hasNextLong()) {
long decimalNum = scanner.nextLong();
System.out.println(decimalNum + " in Binary: " + Long.toBinaryString(decimalNum));
System.out.println(decimalNum + " in Octal: " + Long.toOctalString(decimalNum));
System.out.println(decimalNum + " in Hex: " + Long.toHexString(decimalNum));
}
else {
System.out.println("I want only a number!");
}
}
}``````

### 3. By Dmitry

```255
00000000 00000000 00000000 11111111```
``````public class Program
{
public static void main(String[] args) {
System.out.println(toBinary(255));
}

static String toBinary(int num) {
StringBuilder sb = new StringBuilder();
for(int i=1; i<=32; i++){
sb.append(((num&1)==1)?1:0);
num>>=1;
if (i==8 || i==16 || i==24) sb.append(' ');
}
sb.reverse();
return sb.toString();
}
}``````

### 4. By qwerty

Made by qwerty. Very Basic Decimal to Binary Program. Source

```4
100```
``````import java.util.Scanner;
class Program {
public static void main(String[] args) {
System.out.print(Integer.toBinaryString(new Scanner(System.in).nextInt()));
}
}``````

### 5. By Aya

```x=5
binary=101```
``````import java.util.Scanner;
public class Program
{
public static void main(String[] args) {
Scanner in=new Scanner(System.in);
int x=in.nextInt();
System.out.println("x="+x);
System.out.println("binary=" + Integer.toBinaryString(x));

/*    int P=1,Sum=0,r;
while(x>0){
r=x%2;
Sum+=r*P;
P*=10;
x/=2;}
System.out.print("Sum="+Sum);*/
}

}``````

### 6. By Nilesh

```25
11001 ```
``````public class Program
{
public static void main(String[] args) {
int no = 25;
String z = " ";
int d;
while(no>0)
{
d=no%2;
no = no / 2;
z=d+z;
}
System.out.print(z);
}
}``````

### 7. By Miljan Stojanovic

```Your number is:   7
Binary value is:  111```
``````import java.util.Scanner;

public class ConvertDecimalValueToBinaryValue{
public static void main(String[] args) {

try {
String binary = "";

Scanner input = new Scanner(System.in);
//System.out.println("Enter integer number: ");
int x = input.nextInt();
System.out.printf("%-18s%d\n", "Your number is: ", x);

while (x > 0) {
if (x % 2 == 1) {
binary = 1 + binary;
} else if (x % 2 == 0) {
binary = 0 + binary;
}
x = x / 2;
}

System.out.printf("%-18s%s\n", "Binary value is: ", binary);
}catch (Exception e){
System.out.println("Try again.\nEnter integer number.");
}

}
}``````

### 8. By Aayush Bhansali

```Enter a Number : 8
00001000```
``````import java.util.Scanner;

class Dec2bin {

public void conv (int x)
{
int i = 0;

StringBuffer bits = new StringBuffer();

for (i = 0; i  < 8; i++)
{
bits.append(x % 2);
x = x / 2;
}

String j = bits.reverse().toString();
System.out.println(j);
}
}

public class Program
{
public static void main(String[] args) {

int a;

System.out.println("Enter a Number : ");
Scanner sc = new Scanner(System.in);
a = sc.nextInt();

//Object Creation
Dec2bin b = new Dec2bin();
b.conv(a);
}
}``````

```9
binary value is
1001```
``````import java.util.Stack;
import java.util.Scanner;
public class binary
{
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
Stack<Integer> stack = new Stack<>();
// System.out.println("enter the decimalvalue");
int val = in.nextInt();
while(val != 0)
{
int a = val % 2;
stack.push(a);
val/=2;

}
System.out.println ("binary value is");
while (!(stack.isEmpty()))
{
System.out.print(stack.pop());
/* if(a%2==0)
{
System.out.println("evil number");
}
else
{
System.out.println("odious number");
}*/
}
System.out.println("");
}
}``````

### 10. By kernelpanic_r

Made by kernelpanic_r. This code, will convert your decimal number, to binary, User insert 10, outputs 1010. Source

```Decimal: 10
Binary: 1010```
``````import java.util.InputMismatchException;
import java.util.Scanner;
public class Decimal_Binary {

public static void main(String[] args) {

Scanner in = new Scanner(System.in);
Converter converter = new Converter();

try {

long number = in.nextLong(); // catch the user input
String binary = converter.converterDecimal(number);

System.out.println("Decimal: " + number);
System.out.println("Binary: " + binary);

System.out.println("\n\nThanks!\nMatheus Rambo!");

} catch (InputMismatchException ex) {

}
}
}

class Converter {

protected String converterDecimal(long numberDecimal) {

String binary = "";

for (int i = 0; i < numberDecimal; numberDecimal /= 2) {

binary += numberDecimal % 2;

}

binary = switchElementes(binary); // using the method here!

return binary;
}

private String switchElementes(String binary) {

// just reverse the position !
String returnString = "";

for (int i = binary.length() - 1; i >= 0; i--) {

returnString += binary.charAt(i);
}

return returnString;
}

}``````

### 11. By Denise Roßberg

Made by Denise Roßberg. Input a decimal number (0-255), get binary number. Source

`11 = 00001011`
``````
import java.util.Scanner;

public class Program
{
public static void main(String[] args) {

Scanner input = new Scanner(System.in);
int number = input.nextInt();
int[] b = new int[8];

if(number < 0 || number > 255){

System.out.println("Please input a number between 0-255.");
System.exit(0);
}

System.out.print(number + " = ");

for(int i = 0; i <= 7; i++){

b[i] = number % 2;
number /= 2;

}

for(int i = 7; i >= 0; i--){

System.out.print(b[i]);
}

input.close();
}
}``````

### 12. By Raphael Williams

```Enter the number you want to convert to binary:12
1100```
``````import java.util.Scanner;

public class DecimalToBinary
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int number = sc.nextInt();
sc.close();

System.out.println("Enter the number you want to convert to binary:"+ number);

System.out.println(Integer.toBinaryString(number));
}
}``````

### 13. By Baran

```13
1101```
``````import java.util.Scanner;

class Converter{
public static String toBinary(int x)
{
String binary ="";
while(x>0)
{
binary = (x%2)+binary;
x/=2;
}return binary;
}
}

public class Program {
public static void main(String[ ] args) {
Scanner sc = new Scanner(System.in);
int x = sc.nextInt();
System.out.print(Converter.toBinary(x));
}
}``````

### 14. By Valeria

Made by Valeria. Enter a number between 0 and 255 to see its binary. Source

```Decimal:14
Binary:00001110```
``````/*
I can't use JOptionPane here. I did so on my PC.
*/
//Decimal to binary in range 0 to 255.

//import javax.swing.JOptionPane;
import java.util.Scanner;
public class decimalToBinary {
public static void main(String[] args) {
int arrBinary[] = {128, 64, 32, 16, 8, 4, 2, 1};
int input=0, number=0;
String rest="", binary="";
Scanner sc = new Scanner(System.in);

try {
//number = Integer.parseInt(JOptionPane.showInputDialog("Enter a number between 0 and 255"));
System.out.println("Enter a number between 0 and 255");
input = sc.nextInt();
number = input;
for(int i=0; i<arrBinary.length; i++) {
if(number<0 || number>255) {
//JOptionPane.showMessageDialog(null, "Number   out of range");
System.out.print("Number out of range");
break;
} else if(number == 0) {
binary = "0";
break;
} else if(number % arrBinary[i] == 0) {
binary = binary + "1";
rest = new String(new   char[(8-(i+1))]).replace("\0", "0");
break;
} else if(number - arrBinary[i] > 0) {
number = number - arrBinary[i];
binary = binary + "1";
} else {
binary = binary + "0";
}
}

if(rest!="" || binary!="") {
//JOptionPane.showMessageDialog(null, "Binary\n" + binary + rest);
System.out.print("\nDecimal:" + input + "\nBinary:" + binary + rest);
}
} catch (Exception NumberFormatException) {
System.out.print("End of program.");
}
}
}``````

### 15. By Sayed Anwar Shahen

Made by Sayed Anwar Shahen. Source

```Enter a number: 15
The binary representation is 1111```
``````// A program Decimal to Binary

import java.util.Scanner;
public class DecimalToBinary {
public String toBinary(int n) {
if (n == 0) {
return "0";
}
String binary = "";
while (n > 0)
{
int rem = n % 2;
binary = rem + binary;
n = n / 2;
}
return binary;
}

public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter a number: ");
int decimal = scanner.nextInt();

DecimalToBinary dtb = new DecimalToBinary();
String binary = dtb.toBinary(decimal);
System.out.println("The binary representation is " + binary);
}
}``````

### 16. By Eliya Ben Baruch

Made by Eliya Ben Baruch. Source

```16
10000```
``````import java.util.*;
public class Program {
public static Scanner reader = new Scanner(System.in);
public static void main(String[] args) {
int decimal = reader.nextInt(), divider = 1, count = 0;
StringBuilder binary = new StringBuilder("");
while (decimal > 0 || divider > 0) {
if (decimal / divider < 2 && decimal / divider >= 1) {
decimal -= divider;
divider /= 2;
binary.append("1");
}
else if (decimal / divider >= 2) {
divider *= 2;
count = 0;
}
else {
divider /= 2;
if (count > 1)
binary.append("0");
}
count ++;
}
System.out.println(binary);
}
}``````

### 17. By Airree

Made by Airree. INPUT A NUMBER BETWEEN 32,767 AND -32767, IT WILL BE CONVERTED TO A 16-BIT BINARY NUMBER. Source

```Your Number is: 17
The Number in Binary: 0000000000010001```
``````import java.util.Scanner;

/*
__    ____  ____  ____  ____  ____
/__\  (_  _)(  _ \(  _ \( ___)( ___)
/(__)\  _)(_  )   / )   / )__)  )__)
(__)(__)(____)(_)\_)(_)\_)(____)(____)

*/

public class Program {
public static int[] output_arr = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};
public static String output = "";
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int num = input.nextInt();
if (num > 32767) {
num = 32767;
System.out.println("You shouldn't input Numbers bigger than 32,767\n\nYour Number was changed to 32,767");
} else if (num < -32767) {
num = -32767;
System.out.println("You shouldn't input Numbers smaller than -32,767\n\nYour Number was changed to -32,767");
} else {
System.out.println("Your Number is: " + num);
}
if (num < 0) {
output_arr[15]++;
num = -num;
}
for (int i = 14; i >= 0; i--) {
if (num / Math.pow(2, i) >= 1) {
output_arr[i] = 1;
num -= Math.pow(2, i);
}
}
for (int i = 15; i >= 0; i--) {
output += output_arr[i];
}
System.out.println("The Number in Binary: " + output);
}
}``````

### 18. By Obinna Aguocha

```Enter a decimal number: 18
Binary representation of 18 =10010```
``````import java.util.Scanner;

public class DecimalToBinary {

public static void main(String[] args) {
int decimal;
Scanner in = new Scanner(System.in);
System.out.print("Enter a decimal number: ");
decimal = in.nextInt();
System.out.println("Binary representation of "+decimal+" =" +Integer.toBinaryString(decimal));
}
}``````

### 19. By Bipin Tatkare

Made by Bipin Tatkare. This program is based upon the encryption of numbers that we send as a data in that we first find out the binary number of any given integer data type and then the order of the binary number get reversed and find the value of reversed order ..you will choose numbers between 100 to 2500. Source

```(1)Entered Number is : 19
-------------------------------------------------------
(2)Encrypted Result is : 11001
----------------------------------------------------
(1)Original conversion is : 10011
---------------------------------------------------
(2)Encrypted Message is : 9```
``````import java.lang.Math;
import java.util.*;
public class Program
{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int number = input.nextInt();
System.out.println("(1)Entered Number is : "+number);
System.out.println("-------------------------------------------------------");
int duplicate = number;
String initial = "0";
String finale = "1";
String result = "";
String copy ="";
while(duplicate > 0){

if(duplicate % 2 == 0){

result += initial;

}else{
result += finale;
}

duplicate /= 2;

}
System.out.println("(2)Encrypted Result is : "+result);
System.out.println("----------------------------------------------------");
int length = result.length();
String lele = result;
System.out.print("(1)Original conversion is : ");
for(int i = length - 1;i >= 0; i-- ){

copy += i;
System.out.print(result.charAt(i));

}
System.out.println();
String ander = lele;
int sum2 = 0;
int num = Integer.parseInt(lele);
int letu = num;
for(double j = 0 ; j < ander.length() - 1 ; j++){

double dig = letu % 10;
double save = Math.pow(2 , j);
double let = dig * save;
sum2 += let;
letu /= 10;
}
System.out.println("---------------------------------------------------");
System.out.println("(2)Encrypted Message is : "+sum2);

}
}``````

### 20. By Veer

```Inputted Decimal Number is 20
It's binary conversion is 10100```
``````
import java.util.Scanner;
class Binary{
String convert(int a){
String b="";
int r;
while(a > 0) {
r=a%2;
b = r+b;
a /= 2;
}
return b;
}
}

public class Program {
public static void main(String[ ] args) {
Scanner sc = new Scanner(System.in);
int x = sc.nextInt();
System .out.println ("Inputted Decimal Number is "+x);
Binary b=new Binary();

System.out.println("It's binary conversion is "+b.convert(x));
}
}``````

### 21. By Avi Rzayev

```21
10101```
``````import java.util.*;
public class Program
{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println(binary(input.nextInt()));

}
public static int binary(int x){
return (x == 1)?1:(binary(x / 2) * 10) + (x % 2);
}
}``````

### 22. By Boris Batinkov

Made by Boris Batinkov. How to use: 1. Enter the number 2. Set a binary representation for the number: 0=Auto, 1=Byte, 2=Word, 3=DWord, 4=QWord. Source

```Number: 22
---- ---- ---- ---- ---- ---- ---- ----

0001 0110

---- ---- ---- ---- ---- ---- ---- ----```
``````import java.util.Scanner;

public class Dec_Bin_Convertor
{
// Prints the binary number
public static void printBinaryNumber(long decNum, long bits)
{
String bNum = "";

for (int i = 0; i < bits; i++) {
// Separating on Nibbles (half - bytes)
String space = ((i % 4) == 0 ? " " : "");

// Separating on DWords (double words)
String line = ((i % 32) == 0 ? "\n" : "");

bNum = ((decNum & mask) == 0 ? "0" : "1") + space + line + bNum;
}
System.out.println("\n" + bNum);
}

// Representation of the binary number (Byte, Word, DWord, QWord)
public static long setRepresentation(long decNum, int repNum)
{
long bits = 64;

if (repNum == 1) bits = 8;              // Byte
else if (repNum == 2) bits = 16;        // Word
else if (repNum == 3) bits = 32;        // DWord
else if (repNum == 4) bits = 64;        // QWord
else if (decNum >= Byte.MIN_VALUE && decNum <= Byte.MAX_VALUE) {    // Auto (by the type size)
bits = 8;
}
else if (decNum >= Short.MIN_VALUE && decNum <= Short.MAX_VALUE) {
bits = 16;
}
else if (decNum >= Integer.MIN_VALUE && decNum <= Integer.MAX_VALUE) {
bits = 32;
}

return bits;
}

public static void main(String[] args)
{
Scanner input = new Scanner(System.in);

long decNum = 0;
int repNum = 0;

try {
// Number to convert
decNum = input.nextLong();
try {
// Binary number representation
repNum = input.nextInt();
}
catch (Exception e) {}
}
catch (Exception e) {
System.out.println("(!) Error: Wrong input...");
System.out.println("Line 1: integer up to 64 bits");
System.out.println("Line 2: binary representation number:");
System.out.println("0=Auto, 1=Byte, 2=Word, 3=DWord, 4=QWord");
System.exit(0);
}

long bits = setRepresentation(decNum, repNum);

System.out.println("\nNumber: " + decNum);
System.out.println("---- ---- ---- ---- ---- ---- ---- ----");
printBinaryNumber(decNum, bits);
System.out.println("---- ---- ---- ---- ---- ---- ---- ----");
}
}``````

### 23. By suman Kayal

```binary form of 23 is---
10111```
``````import java.io.*;
public class Program
{
public static void main(String[] args)throws IOException {
int no,re,q;
char ch;
String bi="",n;
//Enter a Integer to get its binary form .
System.out.println("*****Hope you will like this code and hit an upvote *******");
q=no;
while(no!=0){
re=no%2;
bi=bi+re;
no=no/2;
}
System.out.println("binary form of "+q+" is---");
for(int i=bi.length()-1;i>=0;i--){
ch=bi.charAt(i);
System.out.print(ch);

}
}
}``````

### 24. By Up Wala Shiva

Made by Up Wala Shiva. Source

```1 1 0 0 0

Total Binary  digit is =  5```
``````
import java.util.Scanner;
public class Program
{
public static void main(String[] args) {

Scanner st = new Scanner(System.in);

int a = st.nextInt();

String b ="";

int  count=0;
int c[] = new int[50];

while(a>=1)
{

count++;
b =b+count ;

c[count]  = a%2 ;  // only reminder  is stroring
a= a/2 ;

}
System.out.println("    ");

// number is reversing
for(int i=count ;i>=1;i--) //this 'for' loop depends on value of count ;
{
System.out.print(" "+c[i]);
}
System.out.println("\n");
System.out.println("Total Binary  digit is =  "+count);

//******finish*********//
// by Shiva rana ;

}
}``````

```enter a number in decimal system
25
11001```
``````import java.util.Scanner;
public class Program
{
public static void main(String[] args) {  Scanner s=new Scanner(System.in);
String d;
System.out.println
("enter a number in decimal system \n ");
d=s.next();

if(d.contains(",")||d.contains("."))
fNum(d);
else
{
int d1[]=new int[20];
int y=Integer.parseInt(d);
int n=0;
do
{
d1[n]=y%2;
y/=2;
n++;
}while(y!=0);
int i;
for(i=n-1;i>=0;i--)
System.out.printf("%d",d1[i]);
}
}

static void fNum(String d)
{
int d1=0,n1=0,n2=0;
float d2=0;
int bef[]=new int[100];//befor ','
int aft[]=new int[70];
String x="";
int i1;

for(i1=0;i1<d.length();i1++)
{
if(d.charAt(i1)==','||
d.charAt(i1)=='.')
{
x=d.substring(0,i1);
d1=Integer.parseInt(x);
x=d.substring(i1+1,d.length());
d2=(float)Double.parseDouble(x);

while(d2>1)
d2/=10;

break;
}//the previous should be true
}
do
{
bef[n1]=d1%2;
d1/=2;
n1++;
}while(d1!=0);//tht was true
int count=0;
for(;;)
{
d2*=2;
if(d2>=1)
{
aft[n2]=1;
d2-=1;
}
else
aft[n2]=0;
n2++;

count++;
if(count==7||d2==0)
break;
}
int i=n1-1;
while(i>=0)
{
System.out.printf("%d",bef[i]);
i--;
}
System.out.printf(",");
int k=n2,j;
for( j=0;j<k;j++)
{
System.out.printf("%d",aft[j]);
}

}
}``````

### 26. By Shamoil Arsiwala

```Enter Decimal Number 26
Binary Value for 26 is 11010```
``````import java.util.*;
public class D2B
{
static int choice, v, d, i;
static char ch;
static String b = "", s;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter Decimal Number");
v = sc.nextInt();
D2Bf(v);
}

public static void D2Bf(int v)
{
int a = v, t;
while (a != 0){
t = a % 2;
a /= 2;
b = Integer.toString(t) + b;
}
System.out.println("Binary Value for " + v + " is " + b);
}
}``````

### 27. By Ali

Made by Ali. This Java Program can convert a decimal number to hex and octal and binary number. Source

```decimal : 27

hex : 0x1B

octal : 033

binary : 0b11011```
``````
import java.awt.*;
import java.util.*;
interface Main {
void S(String q);
void hex(int x);
void octal(int x);
void binary(int x);
}

public class Program implements Main {
public void S(String q) {
System.out.println("hex : "+q+"\n");}
public void hex(int x) { if(x<256) {
if(x%16<10 && x/16<10) {
S("0x"+(
(((x/256)%16)*100)+(((x/16)%16)*10)
+(x%16)));} else if(x/16<10) {
if(x%16==10) {S("0x"+x/16+"A");}
else if(x%16==11) {S("0x"+x/16+"B");}
else if(x%16==12) {S("0x"+x/16+"C");}
else if(x%16==13) {S("0x"+x/16+"D");}
else if(x%16==14) {S("0x"+x/16+"E");}
else if(x%16==15) {S("0x"+x/16+"F");} }
else if(x/16==10) { if(x%16<10){
S("0xA"+x%16); }
else if(x==170) { S("0xAA"); }
else if(x==171) { S("0xAB"); }
else if(x==172) { S("0xAC"); }
else if(x==174) { S("0xAE"); }
else if(x==175) { S("0xAF"); }
}else if(x/16==11) { if(x%16<10) {
S("0xB"+x%16); }
else if(x==186) { S("0xBA"); }
else if(x==187) { S("0xBB"); }
else if(x==188) { S("0xBC"); }
else if(x==189) { S("0xBD"); }
else if(x==190) { S("0xBE"); }
else if(x==191) { S("0xBF"); }
}else if(x/16==12) { if(x%16<10) {
S("0xC"+x%16); }
else if(x==202) { S("0xCA"); }
else if(x==203) { S("0xCB"); }
else if(x==204) { S("0xCC"); }
else if(x==205) { S("0xCD"); }
else if(x==206) { S("0xCE"); }
else if(x==207) { S("0xCF"); }
}else if(x/16==13) { if(x%16<10) {
S("0xD"+x%16); }
else if(x==218) { S("0xDA"); }
else if(x==219) { S("0xDB"); }
else if(x==220) { S("0xDC"); }
else if(x==221) { S("0xDD"); }
else if(x==222) { S("0xDE"); }
else if(x==223) { S("0xDF"); }
}else if(x/16==14) { if(x%16<10) {
S("0xE"+x%16); }
else if(x==234) { S("0xEA"); }
else if(x==235) { S("0xEB"); }
else if(x==236) { S("0xEC"); }
else if(x==237) { S("0xED"); }
else if(x==238) { S("0xEE"); }
else if(x==239) { S("0xEF"); }
}else if(x/16==15) { if(x%16<10) {
S("0xF"+x%16); }
else if(x==250) { S("0xFA"); }
else if(x==251) { S("0xFB"); }
else if(x==252) { S("0xFC"); }
else if(x==253) { S("0xFD"); }
else if(x==254) { S("0xFE"); }
else if(x==255) { S("0xFF"); }
} } else {System.out.println
("try another number\n");} }

public void octal(int x) { if(x<262144) {
System.out.println
("octal : 0"+( (((x/32768)%8)*100000)+
(((x/512)%8)*1000)+(((x/4096)%8)*10000)+
(((x/64)%8)*100)+(((x/8)%8)*10)+(x%8))+
"\n");}
else { System.out.println(
"try another number\n"); }}

public void binary(int x) { if(x<1024) {
System.out.println("binary : 0b"+(
(x%2)+(((x/2)%2)*10)+(((x/4)%2)*100)
+(((x/8)%2)*1000)+(((x/16)%2)*10000)+
(((x/32)%2)*100000)+(((x/64)%2)*1000000)+
(((x/128)%2)*10000000)+
(((x/256)%2)*100000000)+
(((x/512)%2)*1000000000)
));} else{ System.out.println(
"try another number"); }}}

class result {
public static void main(String[] args) {
try {
Scanner sc = new Scanner(System.in);
int w = sc.nextInt();System.out.println(
"decimal : "+w+"\n");
Main g = new Program();

g.hex(w);
g.octal(w);
g.binary(w); }
catch (Exception a) {
System.out.println("error");
} } }``````

### 28. By Devbrath

```28
11100```
``````import java.util.Scanner;
public class Program
{
//Program to convert Decimal to binary
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int num= sc.nextInt();
int a;
String bin="";
while(num>0){
a=num%2;
bin=a+bin;
num/=2;
}
System.out.println(bin);
System.out.println("If you like it leave a Like");

}
}``````

### 29. By Joshua

```29
11101```
``````import java.util.Scanner;

public class Program {
public static void main(String[] args) {
Scanner inp = new Scanner(System.in);
int dec = inp.nextInt();
String bin = "";
while(dec != 0) {
if(dec % 2 == 1) {
bin = "1" + bin;
}
if(dec % 2 == 0) {
bin = "0" + bin;
}
dec = dec / 2;
}
System.out.println(bin);
}
}
``````

### 30. By Abdol Hashimi

```Input a Decimal Number please : 30
Binary number is: 11110```
``````//This program converts decimal numbet to binary number.

import java.util.Scanner;
public class decimaltobinary {
public static void main(String args[])
{
int decimalnum, rem, quot, i=1, j;
int binarynum[] = new int[100];
Scanner scan = new Scanner(System.in);

System.out.print("Input a Decimal Number please : ");
decimalnum = scan.nextInt();

quot = decimalnum;

while(quot != 0)
{
binarynum[i++] = quot%2;
quot = quot/2;
}

System.out.print("Binary number is: ");
for(j=i-1; j>0; j--)
{

System.out.print(binarynum[j]);
}
System.out.print("\n");
}
}``````

### 31. By Teresa Guerrero

```Decimal number to convert: 31
Binario: 11111 ```
``````import java.util.Scanner;

/**
* Program that converts a decimal number to binary.
*/
public class Program
{
public static void main(String[] args) {
int number, exp, digit;
double binary;
Scanner sc = new Scanner(System.in);

do{
System.out.print ("Decimal number to convert: ");
number = sc.nextInt();
}while(number<0);

exp = 0;
binary = 0;
while(number != 0){
digit = number % 2;
binary = binary + digit * Math.pow(10, exp);
exp++;
number = number/2;
}

System.out.printf("Binario: %.0f %n", binary);
}
}``````

### 32. By gdjogn4s

```Menu:
Decimal to binary.

32
The binary number is --> 100000```
``````/*
* Pls visit my github page for more. (this project in particular, labeled Logical-Programs)
* https://github.com/gdjohn4s
*/

import java.util.*;

public class Program {
static Scanner input = new Scanner(System.in);

public static void main(String[] args) {
decimalBinary();
}

System.out.println(" -john4s  V1.1.4 23/05/2019");
System.out.println("https://github.com/gdjohn4s/Logical-Progams  --For github project \n");
System.out.println("Decimal to binary.\n");
}

public static void decimalBinary() {
int num = input.nextInt();
String binary = Integer.toBinaryString(num);
System.out.println("The binary number is --> " +binary);
System.out.println("\nBinary to decimal incoming!..");
}

}``````

### 33. By Sololearn

```156
10011100```
``````public class DecimalToBinary
{
/* A binary number is made up of elements called bits where each bit can be 1 or 0 */
public static void main(String[] args)
{
int number = 156;

String binary = toBinary(number);
System.out.println(binary);
}

public static String toBinary(int n)
{
if (n == 0)
{
return "0";
}

String binary = "";

while (n > 0)
{
// The % (modulus) operator returns the remainder of the division
int rem = n % 2;
// add the result (0 or 1)
binary = rem + binary;
// divide the number by 2
n = n / 2;
}

return binary;
}
}``````

### 34. By ISkylake

Made by ISkylake. Basic Java Decimal to Binary Converter Program. Source

```34
100010```
``````import java.util.Scanner;

public class Program {
public static void main(String[] args) {
String input = new Scanner(System.in).nextLine();
try {
long num = Long.parseLong(input);
String bin = Long.toBinaryString(num);
System.out.println(bin);
}
catch (Exception e) {
System.out.println("It's not number!");
}
}
}``````

### 35. By viki

```Enter the decimal number: 35
The binary equivalent of the given decimal number 35 is 100011```
``````
import java.util.Scanner;
public class Dec2Bin
{
public static void main(String[] args)

{
Scanner s = new Scanner(System.in);
System.out.println("Enter the decimal number: ");
int num = s.nextInt();

int rem = 0; String bin = "";
int dec = num;

while(dec!=0)
{
rem = dec % 2;
bin = rem+bin;;
dec = dec / 2;
}

System.out.println("The binary equivalent of the given decimal number "+num+" is "+bin);

}
}``````

### 36. By Lucifer

```The number you entered is = 36
The number in binary is= 100100```
``````// Enter a number in decimal

import java.util.*;
public class DecToBinary
{
public static void main(String[] args)
{
long n,r,s=0,p=0;
Scanner sc=new Scanner (System.in);
n=sc.nextInt();
for(long i=n;i>0;i=i/2)
{
r=i%2;
s=s+r*(long)Math.pow(10,p++);
}
System.out.println("The number you entered is = "+n);
System.out.println("The number in binary is= "+s);

}
}``````

### 37. By Ali

Another Java Decimal to Binary Converter Program by Ali. Source

```37
Your number in binary is 100100```
``````import java.util.Scanner;
public class Sistema{
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
float oper=0;
float result=0;
int    number = in.nextInt();
float suma= 0;
int top= 10;

while (number>1){
top= top * 10;
oper = number % 2;
number= number / 2;
suma= (suma + oper) / 10 ;
}

suma = (number + suma) / 10;
result = suma*top;
int solution = (int) result;
System.out.println("Your number in binary is "+solution);
}
}``````

### 38. By Thant Zin Aung

Made by Thant Zin Aung. Source

```Decimal number: 38
Binary number: 100110```
``````import java.util.Scanner;

// Please enter the decimal number first...

public class Program
{
public static void main(String[] args) {
int decNum, tempDec, i=1, j;
int bin_num[] = new int[100];
Scanner scan = new Scanner(System.in);
decNum = scan.nextInt();

tempDec= decNum;

// Algorithm
while(tempDec != 0)
{
bin_num[i++] = tempDec%2;
tempDec = tempDec/2;
}
System.out.println("Decimal number: "+decNum);
System.out.print("Binary number: ");
for(j=i-1; j>0; j--)
{
System.out.print(bin_num[j]);
}
System.out.print("\n");
}
}``````