binary to decimal
unknown
java
10 months ago
417 B
5
Indexable
public class Javafunction{
public static int binToDec(int n){
int pow=0;
int dec=0;
while(n>0){
int lastDigit=n%10;
dec=dec+(lastDigit*(int)Math.pow(2, pow));
pow++;
n=n/10;
}
System.out.println(dec);
return n;
}
public static void main(String args[]){
binToDec(100);
}
}Editor is loading...
Leave a Comment