16进制操作类

class HexCon {
   // 把十六进制字符串转换成字节型和把字节型转换成十六进制字符串 converter hex string to byte and byte to hex string
      public static string ByteToString(byte[] InBytes) {
         string StringOut="";
         foreach (byte InByte in InBytes) {
            StringOut=StringOut + String.Format("{0:X2} ",InByte);
         }
         return StringOut; 
      }
      public static byte[] StringToByte(string InString) {
         string[] ByteStrings;
         ByteStrings = InString.Split(" ".ToCharArray());
         byte[] ByteOut;
         ByteOut = new byte[ByteStrings.Length-1];
         for (int i = 0;i==ByteStrings.Length-1;i++) {
            ByteOut[i] = Convert.ToByte(("0x" + ByteStrings[i]));
         } 
         return ByteOut;
      }
   }

posted on 2020-07-18 21:56  xihong  阅读(134)  评论(0编辑  收藏  举报

导航