积极答复者
c# 如何将十六进制四个字节的byte[]转成四个字节的float 型

问题
答案
-
你可以看看这个示例的:http://code.msdn.microsoft.com/CSHexStringByteArrayConvert-a80e955d
上面的示例演示了把16进制转化为字符串,你可以参考上面的代码来实现你的需求,主要区别是对16进制的解析不一样
If my post is helpful,please help to vote as helpful, if my post solve your question, please help to make it as answer. my sample
- 已建议为答案 Learning hard 2013年6月10日 18:22
- 已标记为答案 Bob ShenModerator 2013年6月20日 10:20
-
hello,
你是要用byte[]转吗,但你的发问内容是用char,你可参考以下的做法
BitConverter.ToSingle BitConverter.Int64BitsToDouble
http://www.dotblogs.com.tw/yc421206/archive/2013/04/03/99840.aspx
秘訣無它,唯勤而已 http://www.dotblogs.com.tw/yc421206/
- 已编辑 余小章MVP 2013年6月4日 3:40
- 已建议为答案 Learning hard 2013年6月10日 18:23
- 已标记为答案 Bob ShenModerator 2013年6月20日 10:20
全部回复
-
没有看懂你的意思——你转换规律是什么?最好举一个例子,谢谢。
If you think one reply solves your problem, please mark it as An Answer, if you think someone's reply helps you, please mark it as a Proposed Answer
Help by clicking:
Click here to donate your rice to the poor
Click to Donate
Click to feed Dogs & Cats
Found any spamming-senders? Please report at: Spam Report -
你可以看看这个示例的:http://code.msdn.microsoft.com/CSHexStringByteArrayConvert-a80e955d
上面的示例演示了把16进制转化为字符串,你可以参考上面的代码来实现你的需求,主要区别是对16进制的解析不一样
If my post is helpful,please help to vote as helpful, if my post solve your question, please help to make it as answer. my sample
- 已建议为答案 Learning hard 2013年6月10日 18:22
- 已标记为答案 Bob ShenModerator 2013年6月20日 10:20
-
具体实现代码可以参考下面的文章来实现:
http://www.csharpwin.com/csharpspace/6229r367.shtml
http://www.360doc.com/content/11/1103/22/3810344_161489474.shtml
If my post is helpful,please help to vote as helpful, if my post solve your question, please help to make it as answer. my sample
-
标准C的程序 :
float string_tofloar(unsigned char c[8])
{
union{unsigned char car[4];
float r;}temp;
temp.car[0]=(c[1]-0x30)*16+c[0];
temp.car[1]=(c[3]-0x30)*16+c[2];
temp.car[2]=(c[5]-0x30)*16+c[4];
temp.car[3]=(c[7]-0x30)*16+c[6];
return temp.r;
}
这个程序是示意程序,没有去编译,在参数传递上有可能有问题,可能要用指针,但思路是这样。我要飞得更远!
-
标准C的程序 :
float string_tofloar(unsigned char c[8])
{
union{unsigned char car[4];
float r;}temp;
temp.car[0]=(c[1]-0x30)*16+c[0];
temp.car[1]=(c[3]-0x30)*16+c[2];
temp.car[2]=(c[5]-0x30)*16+c[4];
temp.car[3]=(c[7]-0x30)*16+c[6];
return temp.r;
}
这个程序是示意程序,没有去编译,在参数传递上有可能有问题,可能要用指针,但思路是这样,不知道如何转成c#www.shshunfu.com
-
那个连接?
www.shshunfu.com
具体实现代码可以参考下面的文章来实现:
http://www.csharpwin.com/csharpspace/6229r367.shtml
http://www.360doc.com/content/11/1103/22/3810344_161489474.shtml
If my post is helpful,please help to vote as helpful, if my post solve your question, please help to make it as answer. my sample
-
-
尝试用C++封装成类库函数,然后C#中DllImport调用。
If you think one reply solves your problem, please mark it as An Answer, if you think someone's reply helps you, please mark it as a Proposed Answer
Help by clicking:
Click here to donate your rice to the poor
Click to Donate
Click to feed Dogs & Cats
Found any spamming-senders? Please report at: Spam Report -
hello,
你是要用byte[]转吗,但你的发问内容是用char,你可参考以下的做法
BitConverter.ToSingle BitConverter.Int64BitsToDouble
http://www.dotblogs.com.tw/yc421206/archive/2013/04/03/99840.aspx
秘訣無它,唯勤而已 http://www.dotblogs.com.tw/yc421206/
- 已编辑 余小章MVP 2013年6月4日 3:40
- 已建议为答案 Learning hard 2013年6月10日 18:23
- 已标记为答案 Bob ShenModerator 2013年6月20日 10:20