fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void show(int n, int acc)
  11. {
  12. if (n < 0) n = 65536 + n;
  13. if (acc == 0) return;
  14. show(n >> 1, acc - 1);
  15. System.out.print(n % 2);
  16. }
  17. public static void main (String[] args) throws java.lang.Exception
  18. {
  19. System.out.print("5 the bits is ");
  20. show(5, 16);
  21. System.out.println();
  22. System.out.print("-5 the bits is ");
  23. show(-5, 16);
  24. System.out.println();
  25. }
  26. }
Success #stdin #stdout 0.11s 320576KB
stdin
Standard input is empty
stdout
5 the bits is 0000000000000101
-5 the bits is 1111111111111011