fork download
  1. class T {
  2. public static byte toBCD(int n)
  3. {
  4. // a*10 + b -> a*16 + b;
  5. byte a = (byte)(n / 10);
  6. byte b = (byte)(n % 10);
  7.  
  8. return (byte) (a * 0x10 + b);
  9. }
  10.  
  11. public static void main(String[] args)
  12. {
  13. assert(toBCD(11) == 0x11);
  14. assert(toBCD(28) == 0x28);
  15. }
  16. }
Success #stdin #stdout 0.02s 245632KB
stdin
Standard input is empty
stdout
Standard output is empty