package com.chenyang.nse.bussiness.tools.dmp;

public class DmpCommonTool {
   static char[] map = new char[]{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};

   public static int binary16_10(String str) {
      return Integer.parseInt(str, 16);
   }

   public static String subZeroAndDot(String s) {
      if (s.indexOf(".") > 0) {
         s = s.replaceAll("0+?$", "");
         s = s.replaceAll("[.]$", "");
      }

      return s;
   }

   public static String toHex(byte b) {
      int i = b & 255;
      String s = "";
      if (null != Integer.toHexString(i)) {
         s = Integer.toHexString(i).toUpperCase();
         if (s.length() == 1) {
            s = '0' + s;
         }
      } else {
         System.out.println("btye is:" + b + ":toHex 方法：十进制数转换为十六进制字符串时返回了NULL!");
      }

      return s;
   }

   public static String toInt(byte b) {
      int i = b & 255;
      String s = "";
      s = s + i;
      return s;
   }

   public static String intToHex(int num) {
      if (num == 0) {
         return "0";
      } else {
         String result;
         for(result = ""; num != 0; num >>>= 4) {
            int x = num & 15;
            result = map[x] + result;
         }

         return result;
      }
   }
}
