不同类型的数据和十六进制的转换

 获取数据 拆分成单个字符
            this.tb_OHex.Text = "";
            string result = "";
            ConvertFloatToHex( float.Parse(this.textBox4.Text.Trim()));
            shangList.Reverse();
            for (int i = 0; i < shangList.Count; i++)
   {
                result += shangList[i].ToString();
   }
            if (xiaolist.Count > 0)
            {
                result += ".";
                xiaolist.Reverse();
                for (int j = 0; j < xiaolist.Count; j++)
                {
                    result += xiaolist[j].ToString();
                }
            }
            tb_OHex.Text = result;

 

 private void ConvertStrToHex(string str)
        {
            string tempHex = "";
            str = str.Replace(" ", "");
            string HexValue="";
            char strTemp;
            int strLen = str.Length;//获取字符长度
            for (int i = 0; i < strLen; i++)
            {
              
               strTemp=str[i];
               int ascValue = Convert.ToChar(strTemp);//获取字符串中每个字符串ASCII码值 
               string asc = ascValue.ToString();             
           
               tempHex = String.Format("{0:X}", ascValue);//获取十六进制值的ASCII码
           
             
               HexValue += tempHex;
            }
            ConverHexstrToBytes(HexValue);
        }

 

posted @ 2011-10-27 12:33  Devil_jim  阅读(238)  评论(0编辑  收藏  举报