I wrote the code and it passes almost all the cases i put manually except for a number other than 0 or 1, it just gives 0 if tested for 4 or 5 or any number. But when I submit the code both the test cases fail. Please help me.
import java.util.Scanner;
public class Binary {
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
int N = scn.nextInt();
int base = 1;
int temp = N;
int value = 0;
while(temp > 0) {
int rem = temp%10;
temp = temp/10;
if(rem == 1 || rem == 0) {
value += rem*base;
base = base * 2;
}
}
System.out.println(value);
}
}