Least Common Multiple(LCM) is a method to find the smallest common multiple between any two or more numbers. A common multiple is a number which is a multiple of two or more numbers.
Program:
class NtoB{
public static void main(String args[]){
int no = 12;
int div=2;
String binary=””;
int remainder =0;
while(no>0) {
remainder =no%2;
binary = remainder+binary;
no=no/2;
}
System.out.println("the binary word is "+binary);
}
}
output:
sobhika@sobhika-HP-Laptop-15-db1xxx:~$ javac LCM.java
sobhika@sobhika-HP-Laptop-15-db1xxx:~$ java LCM
the lcm is 30
Binary to Decimal:
Binary to decimal conversion is done to convert a number in a binary number system (base-2) to a number in a decimal number system (base-10). It is very necessary to understand the binary to decimal conversion for computer programming applications.
Program:
class BtoN{
public static void main(String args[]){
int no=1111;
int pow=0;
double result=0;
while(no>0) {
int last = no%10;
result=result+last*Math.pow(2,pow);
no=no/10;
pow++;
}
System.out.println(result);
}
}
output:
sobhika@sobhika-HP-Laptop-15-db1xxx:~$ javac BtoN.java
sobhika@sobhika-HP-Laptop-15-db1xxx:~$ java BtoN
15.0
Decimal to Binary:
In decimal to binary conversion, we convert a base 10 number to a base 2 number by using simple methods. For example, if 1210 is a decimal number then its equivalent binary number is 11002
Program:
class NtoB{
public static void main(String args[]){
int no = 12;
int div=2;
String binary=””;
int remainder =0;
while(no>0) {
remainder =no%2;
binary = remainder+binary;
no=no/2;
}
System.out.println("the binary word is "+binary);
}
}
output:
sobhika@sobhika-HP-Laptop-15-db1xxx:~$ javac NtoB.java
sobhika@sobhika-HP-Laptop-15-db1xxx:~$ java NtoB
the binary word is 1100