Hey!

i need your help!

For many hours I’m sitting on this code and i can’t find the mistake:

```
public static int dezimalzahlUmwandelnVorwaerts(int decimalInbinaer) {
for (int i = 100 ; i >= 0; i--) {
while (decimalInbinaer >= (int) Math.pow(2, i)) {
if (decimalInbinaer >= (int) Math.pow(2, i)) {
System.out.print("1");
}
else {
System.out.println("0");
}
decimalInbinaer -= Math.pow(2, i);
}
}
return decimalInbinaer;
}
```

}

The test number was 1543.

My program always prints out: “11111”

However the right binary number should be: “11000000111”

It seems, that only the if condition is checked. But the else if condition (which prints out the zeros) is ignored.

Can someone help me?

I know how to solve this problem with “%” and dividing. However than the binary number is printed out backwards.

However i want to use the potency method, thus the binary is printed out forward.

Also I’m not allowed to use any other Methods in Java e.g. “Integer.parseInt(value, 2);”

Thank you very much for your help!