請(qǐng)廣大網(wǎng)友幫忙把編程語(yǔ)言給轉(zhuǎn)換一下
public string float_TO_string(float fl)
{
byte[] a = BitConverter.GetBytes(fl);
return a[0].ToString("X2") + a[1].ToString("X2") + a[2].ToString("X2") + a[3].ToString("X2");
}
public string float_TO_string(double dl)
{
byte[] a = BitConverter.GetBytes(dl);
return a[0].ToString("X2") + a[1].ToString("X2") + a[2].ToString("X2") + a[3].ToString("X2")+ a[4].ToString("X2") + a[5].ToString("X2") + a[6].ToString("X2") + a[7].ToString("X2");
}
public float string_TO_float(string f1)
{
byte[] a = new byte[4];
a[0] = Convert.ToByte(f1.Substring(0, 2));
a[1] = Convert.ToByte(f1.Substring(2, 2));
a[2] = Convert.ToByte(f1.Substring(4, 2));
a[3] = Convert.ToByte(f1.Substring(6, 2));
return BitConverter.ToSingle(a, 0);
}
public double string_TO_double(string d1)
{
byte[] a = new byte[8];
a[0] = Convert.ToByte(d1.Substring(0, 2));
a[1] = Convert.ToByte(d1.Substring(2, 2));
a[2] = Convert.ToByte(d1.Substring(4, 2));
a[3] = Convert.ToByte(d1.Substring(6, 2));
a[4] = Convert.ToByte(d1.Substring(8, 2));
a[5] = Convert.ToByte(d1.Substring(10, 2));
a[6] = Convert.ToByte(d1.Substring(12, 2));
a[7] = Convert.ToByte(d1.Substring(14, 2));
return BitConverter.ToDouble(a, 0);
}