
几个delphi方法,转为C#语言,谢谢 5
//************字节转换成实数********************functionbyte2toSingle(f:arrayofbyte):single;...
//************字节转换成实数********************
function byte2toSingle(f:array of byte) : single;
type
pSingle = ^TSingle ;
TSingle = record
Case Integer Of
0: (AsSingle:Single);
1: (FirstHi,FirstLo,SecondHi,SecondLo:Byte);
End;
Var
p : PSingle;
S : Single;
begin
P := @S ; // 让P 指向S 的位址(使用同一块记忆体)
// 改变P的值也等於改变S值
// 将取得的16进位字串一个Byte一个Byte塞进Single中
P.FirstHi := f[1];
P.FirstLo := f[0];
P.SecondHi:= f[3];
P.SecondLo:= f[2];
result:=P.AsSingle;
end; 展开
function byte2toSingle(f:array of byte) : single;
type
pSingle = ^TSingle ;
TSingle = record
Case Integer Of
0: (AsSingle:Single);
1: (FirstHi,FirstLo,SecondHi,SecondLo:Byte);
End;
Var
p : PSingle;
S : Single;
begin
P := @S ; // 让P 指向S 的位址(使用同一块记忆体)
// 改变P的值也等於改变S值
// 将取得的16进位字串一个Byte一个Byte塞进Single中
P.FirstHi := f[1];
P.FirstLo := f[0];
P.SecondHi:= f[3];
P.SecondLo:= f[2];
result:=P.AsSingle;
end; 展开
1个回答
展开全部
看不懂你那个函数的代码,你还不如直接告诉你需要的功能就直接帮你写一个函数不就解决了,下面两个根据你描述的内容写的,供你参考。
private Single byte2single(byte by)//将byte转换为single类型
{
return Convert.ToSingle(by);
}
private Single[] byte2single(byte[] by) //将byte数组转换为single数组类型
{
Single[] reslut = new Single[by.Length];
for (int i = 0; i < by.Length; i++)
{
reslut[i] = Convert.ToSingle(by[i]);
}
return reslut;
}
C#就是牛啊,写程序极其简单又逻辑分明,让人一看就懂。
要说C#就是牛啊,
private Single byte2single(byte by)//将byte转换为single类型
{
return Convert.ToSingle(by);
}
private Single[] byte2single(byte[] by) //将byte数组转换为single数组类型
{
Single[] reslut = new Single[by.Length];
for (int i = 0; i < by.Length; i++)
{
reslut[i] = Convert.ToSingle(by[i]);
}
return reslut;
}
C#就是牛啊,写程序极其简单又逻辑分明,让人一看就懂。
要说C#就是牛啊,
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询