5,388
社区成员
发帖
与我相关
我的任务
分享
procedure TForm1.btn1Click(Sender: TObject);
function BintoInt(Value:String):LongInt;
var
i,Size:Integer;
begin
Result:=0;
Size:=Length(Value);
for i:=Size downto 1 do
begin
if Copy(Value,i,1)='1' then
begin
Result:=Result+(1 shl (Size-i));
end;
end;
end;
var
i,iExponent,iMantissa:Integer;
temp:Int64;
strBinValue,strExponent,strMantissa:string;
strExponentComplement,strMantissaComplement:string;
begin
temp:=StrToInt64('$'+edt1.Text);
//--Get Bin Value
for i:=32-1 downto 0 do
begin
if temp and (1 shl i)<>0 then
begin
strBinValue:=strBinValue+'1';
end else
begin
strBinValue:=strBinValue+'0';
end;
end;
//--Get exponent,mantissa string
strExponent:=Copy(strBinValue,1,8);
strMantissa:=Copy(strBinValue,9,24);
//--2's complement form
if Copy(strExponent,1,1)='1' then
begin
for i:=1 to Length(strExponent) do
begin
if Copy(strExponent,i,1)='1' then
begin
strExponentComplement:=strExponentComplement+'0';
end else
begin
strExponentComplement:=strExponentComplement+'1';
end;
end;
iExponent:=0-(BintoInt(strExponentComplement)+1);
end else
begin
iExponent:=(BintoInt(strExponent));
end;
if Copy(strMantissa,1,1)='1' then
begin
for i:=1 to Length(strMantissa) do
begin
if Copy(strMantissa,i,1)='1' then
begin
strMantissaComplement:=strMantissaComplement+'0';
end else
begin
strMantissaComplement:=strMantissaComplement+'1';
end;
end;
iMantissa:=0-(BintoInt(strMantissaComplement)+1);
end else
begin
iMantissa:=BintoInt(strMantissa);
end;
case iMantissa of
$7FFFFF:ShowMessage('Not a Number');
$800000:ShowMessage('Not at this resolution');
$7FFFFE:ShowMessage('+INFINITY');
$800002:ShowMessage('-INFINITY');
else
ShowMessage(FloatToStr(Power(10,iExponent) * iMantissa));
end;
end;
00FFFFFB 这个值应该是 -5
procedure TForm1.btn1Click(Sender: TObject);
function BintoInt(Value:String):LongInt;
var
i,Size:Integer;
begin
Result:=0;
Size:=Length(Value);
for i:=Size downto 1 do
begin
if Copy(Value,i,1)='1' then
begin
Result:=Result+(1 shl (Size-i));
end;
end;
end;
var
i,iExponent,iMantissa:Integer;
temp:Int64;
strBinValue,strExponent,strMantissa:string;
strExponentComplement,strMantissaComplement:string;
begin
temp:=StrToInt64('$'+edt1.Text);
//--Get Bin Value
for i:=32-1 downto 0 do
begin
if temp and (1 shl i)<>0 then
begin
strBinValue:=strBinValue+'1';
end else
begin
strBinValue:=strBinValue+'0';
end;
end;
//--Get exponent,mantissa string
strExponent:=Copy(strBinValue,1,8);
strMantissa:=Copy(strBinValue,9,24);
//--2's complement form
if Copy(strExponent,1,1)='1' then
begin
for i:=1 to Length(strExponent) do
begin
if Copy(strExponent,i,1)='1' then
begin
strExponentComplement:=strExponentComplement+'0';
end else
begin
strExponentComplement:=strExponentComplement+'1';
end;
end;
iExponent:=0-(BintoInt(strExponentComplement)+1);
end else
begin
iExponent:=(BintoInt(strExponent));
end;
iMantissa:=BintoInt(strMantissa);
case iMantissa of
$7FFFFF:ShowMessage('Not a Number');
$800000:ShowMessage('Not at this resolution');
$7FFFFE:ShowMessage('+INFINITY');
$800002:ShowMessage('-INFINITY');
else
ShowMessage(FloatToStr(Power(10,iExponent) * iMantissa));
end;
end;
procedure TForm1.btn1Click(Sender: TObject);
var
i:Integer;
temp:Int64;
Str_BinValue,Str_Exponent,Str_Mantissa:string;
begin
temp:=StrToInt64('$'+edt1.Text);
//--Get Bin Value
for i:=0 to 32-1 do
begin
if temp and (1 shl i)<>0 then
begin
Str_BinValue:=Str_BinValue+'1';
end else
begin
Str_BinValue:=Str_BinValue+'0';
end;
end;
//--Get exponent,mantissa string
Str_Exponent:=Copy(Str_BinValue,1,8);
Str_Mantissa:=Copy(Str_BinValue,9,24);
//--2's complement form (2的补码)
//--转换成整数
//--判断exponent大于还是小于0
//--(mantissa) * 10 的 exponent
end;
大概是这样 ,下班了 不写了