I think you will want to replace this code
public String binarise(int x) {
if(x==0)
return "";
if(x%2==1)
return "1"+binarise(x/2);
return "0"+binarise(x/2);
}
with
public String binarise(int x) {
if(x==0)
return "";
if(x%2==1)
return binarise(x/2)+"1";
return binarise(x/2)+"0";
}
as I suspect a bug there.