fork download
  1. class Ideone
  2. {
  3. public static void main (String[] args)
  4. {
  5. humanize(42);
  6. humanize(1024 * 1024);
  7. humanize(8192);
  8. humanize(1073741824L * 4L);
  9. humanize(Long. MAX_VALUE);
  10. }
  11. static void humanize(long size)
  12. {
  13. int x = (Long.SIZE-Long.numberOfLeadingZeros(size))/10;
  14. System.out.println((size>>(x*10))+""+"BKMGTPE".charAt(x));
  15. }
  16.  
  17. }
Success #stdin #stdout 0.12s 35792KB
stdin
Standard input is empty
stdout
42B
1M
8K
4G
7E