- private static Byte[] ConvertFrom(string strTemp)
- {
- try
- {
- if (Convert.ToBoolean(strTemp.Length & 1))
- {
- strTemp = "0" + strTemp;
- }
- Byte[] aryTemp = new Byte[strTemp.Length / 2];
- for (int i = 0; i < (strTemp.Length / 2); i++)
- {
- aryTemp[i] = (Byte)(((strTemp[i * 2] - '0') << 4) | (strTemp[i * 2 + 1] - '0'));
- }
- return aryTemp;
- }
- catch
- { return null; }
- }
-
-
-
-
-
- public static Byte[] ConvertFrom(string strTemp, int IntLen)
- {
- try
- {
- Byte[] Temp = ConvertFrom(strTemp.Trim());
- Byte[] return_Byte = new Byte[IntLen];
- if (IntLen != 0)
- {
- if (Temp.Length < IntLen)
- {
- for (int i = 0; i < IntLen - Temp.Length; i++)
- {
- return_Byte[i] = 0x00;
- }
- }
- Array.Copy(Temp, 0, return_Byte, IntLen - Temp.Length, Temp.Length);
- return return_Byte;
- }
- else
- {
- return Temp;
- }
- }
- catch
- { return null; }
- }
-
-
-
-
-
- public static string ConvertTo(Byte[] AData)
- {
- try
- {
- StringBuilder sb = new StringBuilder(AData.Length * 2);
- foreach (Byte b in AData)
- {
- sb.Append(b >> 4);
- sb.Append(b & 0x0f);
- }
- return sb.ToString();
- }
- catch { return null; }
- }
posted @
2017-03-11 11:16
赵栎安
阅读(
3088)
评论()
编辑
收藏
举报