Input is a decimal number and the output is supposed to be that same number in binary form in an ArrayList, but for some reason it is only outputting 1s
Digit is a class whose only value is an int "bit" and a 2-bit adder.
private ArrayList<Digit> numbers;
private Digit number;
public Converter(int val){
numbers = new ArrayList<Digit>();
number = new Digit(val);
if (val == 1 || val == 0){
numbers.add(number);
} else{
while (val >= 1){
number.setValue(val % 2);
numbers.add(number);
val = val/2;
}
}
}
public String toString(){
return "" + numbers;
}
This is outputting the correct number of elements, but all of them are 1s.
ex. 5 = 1,1,1 rather than 1,0,1.