- /// <summary>
- /// 16 转换成float 2字节
- /// 不能有空格或者- 之类的 必须连续例如 6546D43E
- /// </summary>
- /// <param name="p_strRaw"></param>
- /// <returns></returns>
- float HexToFloat(string p_strRaw)
- {
- int len = p_strRaw.Length;
- byte[] TempArry = new byte[len / 2];
- for (int i = 0; i < len / 2; i++)
- {
- TempArry[i] = Convert.ToByte(p_strRaw.Substring(i * 2, 2), 16);
- }
- return BitConverter.ToSingle(TempArry, 0);
- }
- /// <summary>
- /// 16 转换成Int16 2字节
- /// </summary>
- /// <param name="p_strRaw"></param>
- /// <returns></returns>
- Int16 HexToInt16(string p_strRaw)
- {
- int len = p_strRaw.Length;
- byte[] TempArry = new byte[len / 2];
- for (int i = 0; i < p_strRaw.Length / 2; i++)
- {
- TempArry[i] = Convert.ToByte(p_strRaw.Substring(i * 2, 2), 16);
- }
- return BitConverter.ToInt16(TempArry, 0);
- }
- #endregion
- //该片段来自于http://www.codesnippet.cn/detail/0707201614802.html
来源: http://www.codesnippet.cn/detail/0707201614802.html