- 1,395

- 0

## Main Question or Discussion Point

i was told to build a program that transforms a number from deximal basis

into binary basis

i have built it but i get the resolt reversed

for the number 4 i get 001 instead of 100

i know it happening because the last digit comes last

how to change this method so it will show me the right resolt??

into binary basis

i have built it but i get the resolt reversed

for the number 4 i get 001 instead of 100

i know it happening because the last digit comes last

how to change this method so it will show me the right resolt??

Code:

```
public class binar {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
binary(4);
}
public static void binary(int n){
binar(n,"");
}
public static void binar(int n,String str){
if (n==0){
System.out.println(str);
}
else
binar((int)Math.floor(n/2),str+(n%2));
}
}
```