1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. public class IntegerPrinter {
  2. public String printIntegerAsBinary(int value){
  3. StringBuilder binary = new StringBuilder();
  4. while(value >= 1) {
  5. if (value / 2 >= 1) binary.append(value % 2);
  6. value /= 2;
  7. }
  8. return binary.append("1").reverse().toString();
  9. }
  10. public String printIntegerAsOctal(int value){
  11. StringBuilder baseEight = new StringBuilder();
  12. while((value/8) >= 1){//
  13. baseEight.append(value % 8);
  14. value /= 8;
  15. }
  16. return baseEight.append(value).reverse().toString();
  17. }
  18. public String printIntegerAsHexadecimal(int value){
  19. StringBuilder baseSixteen = new StringBuilder();
  20. while((value/16) != 0){
  21. if ((value / 16) >= 1) {
  22. if((value%16) >= 10){
  23. baseSixteen.append((char) (87+(value%16)));
  24. }
  25. else{
  26. baseSixteen.append(value % 16);
  27. }
  28. value /= 16;
  29. }
  30. }
  31. value = value >= 10 ? (char) 87+(value%16) : value;
  32. return baseSixteen.append(value).reverse().toString();
  33. }
  34. public static void main(String[] args){
  35. }
  36. }