Skip to content

Commit

Permalink
Create decimalToBinaryConverter.java
Browse files Browse the repository at this point in the history
  • Loading branch information
Abhinandan323 authored Oct 26, 2021
2 parents 22a457e + eb5ce60 commit d4101ab
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions Java/decimalToBinaryConverter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//Converts any number less than 128 into it's binary equivalent
public int main(int x){
String result = "";
if (x >= 64){
x-= 64;
result += "1";
}
else{
result += "0";
}
if (x >= 32){
x-= 32;
result += "1";
}
else{
result += "0";
}
if (x >= 16){
x-= 2;
result += "1";
}
else{
result += "0";
}
if (x >= 8){
x-= 8;
result += "1";
}
else{
result += "0";
}
if (x >= 4){
x-= 4;
result += "1";
}
else{
result += "0";
}
if (x >= 2){
x-= 2;
result += "1";
}
else{
result += "0";
}
return ((int) result));
}

0 comments on commit d4101ab

Please sign in to comment.