62,046
社区成员
发帖
与我相关
我的任务
分享
byte[] bytes = new byte[4];
bytes[0] = 0x47;
bytes[1] = 0x7A;
bytes[2] = 0x45;
bytes[3] = 0xC2;
float m = BitConverter.ToSingle(bytes, 0);
string s = "477A45C2";
MatchCollection matches = Regex.Matches(s, @"[0-9A-Fa-f]{2}");
byte[] bytes = new byte[matches.Count];
for (int i = 0; i < bytes.Length; i++)
bytes[i] = byte.Parse(matches[i].Value, NumberStyles.AllowHexSpecifier);
float m = BitConverter.ToSingle(bytes, 0);
Response.Write(m);
void short(char s[]) //数组s[]里面存放键盘输入的16进制数
{
int n=0;
for(i=0;s[i]!='\0';i++)
{
if(s[i]>='0'&&s[i]<='9')
n=n*16+s[i]-'0';
if(s[i]>='a'&&s[i]<='f')
n=n*16+s[i]-'a'+10;
if(s[i]>='A'&&s[i]<='F')
n=n*16+s[i]-'A'+10;
}