Programming languages often have built-in routines to convert a non-negative integer for printing in different number bases. Such common number bases might include binary, Octal and Hexadecimal.



Task

Print a small range of integers in some different bases, as supported by standard routines of your programming language.



Note

This is distinct from Number base conversion as a user-defined conversion function is not asked for.)

The reverse operation is Common number base parsing.




/* NetRexx */
options replace format comments java crossref symbols nobinary
 
import java.util.Formatter
 
loop i_ = 1 to 3
  loop n_ = 20 to 20000 by 2131
    select case i_
      when 1 then say useBif(n_)
      when 2 then say useJavaFormat(n_)
      when 3 then say useJavaNumber(n_)
      otherwise nop
      end
    end n_
  say
end i_
 
return
 
-- NetRexx doesn't have a decimal to octal conversion
method useBif(n_) public static
  d_ = '_'
  return '[Base 16='n_.d2x().right(8)',Base 10='n_.right(8)',Base 8='d_.right(8)',Base 2='n_.d2x().x2b().right(20)']'
 
-- Some of Java's java.lang.Number classes have conversion methods
method useJavaNumber(n_) public static
  nx = Long.toHexString(n_)
  nd = Long.toString(n_)
  no = Long.toOctalString(n_)
  nb = Long.toBinaryString(n_)
  return '[Base 16='Rexx(nx).right(8)',Base 10='Rexx(nd).right(8)',Base 8='Rexx(no).right(8)',Base 2='Rexx(nb).right(20)']'
 
-- Java Formatter doesn't have a decimal to binary conversion
method useJavaFormat(n_) public static
  fb = StringBuilder()
  fm = Formatter(fb)
  fm.format("[Base 16=%1$8x,Base 10=%1$8d,Base 8=%1$8o,Base 2=%2$20s]", [Object Long(n_), String('_')])
  return fb.toString()
 