二进制转换十进制程序有错
我这里有个二进制转换十进制的程序代码,但是得到的结果是错误的,请各位大侠帮忙看看哪里出错了,加以指正,谢谢using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using
using System.Runtime.InteropServices;
public partial class Default5 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
FileStream fs = File.OpenRead(@"e:\1111.txt");
int k =0;
byte[] mydata=new byte[fs.Length];
fs.Read(mydata, 0, mydata.Length);
for(int g = 1;g< 3 ;g++)//' 列数-1
{
fudian(mydata[k], mydata[k + 1], mydata[k + 2], mydata[k + 3]); //调用函数fudian
k = k + 4 ;//‘四位二进制转换成一位数字
}
}
public void fudian(byte a0, byte a1, byte a2, byte a3)
{
byte[] a = new byte[4];
a[0] = a0;
a[1] = a1;
a[2] = a2;
a[3] = a3;
//先用一个临时数组倒序数组A
byte[] B = new byte[4];
for(int i = 0;i<4;i++)
{
B[i] = a[3 - i];
}
int size = Marshal.SizeOf(B[0]) * B.Length;
IntPtr Result = Marshal.AllocHGlobal(size);
Marshal.Copy(B,0,Result,4);
Response.Write((float)Result);
}
}