微慑信息网

[DelPHi] Delphi 进制转换——十六进制 to 十进制浮点数

//十进制 to 二进制
function IntToBin(Value: LongInt;Size: Integer): String;
var
i: Integer;
begin
Result:='';
for i:=Size-1 downto 0 do begin
if Value and (1 shl i)<>0 then begin
Result:=Result+'1';
end else begin
Result:=Result+'0';
end;
end;
end;
//二进制 to 十进制
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
Result:=Result+(1 shl (Size-i));
end;
end;
function floatBintoInt(Value: String): real;
var
i,Size: Integer;
begin
Result:=0;
Size:=Length(Value);
for i:=Size downto 1 do
begin
if Copy(Value,i,1)='1' then
Result:=Result+1/(1 shl i);
end;
end;
//十六进制 to 二进制
function HextoBinary(Hex:string):string;
const
BOX: array [0..15] of string =
('0000','0001','0010','0011',
'0100','0101','0110','0111',
'1000','1001','1010','1011',
'1100','1101','1110','1111');
var
i:integer;
begin
for i:=Length(Hex) downto 1 do
Result:=BOX[StrToInt('$'+Hex[i])]+Result;
end;
//十六进制 to 十进制 浮点型
function HextoFloat(s:string):real;
var b,temp:string;
e:integer;
f:real;
begin
b:=HextoBinary(s);
temp := copy(b,2,8);
e:=BintoInt(temp)-127;
temp := copy(b,10,23);
f := 1+floatBintoInt(temp);
if(copy(b,1,1)='0')then
result := power(2,e)*f
else
result :=-power(2,e)*f;
end;
posted on 2006-08-07 17:48 goodmro9 阅读(1271) 评论(1) 编辑 收藏 所属分类: Delphi

赞(0) 打赏
转载请附本站链接,未经允许不得转载,,谢谢:微慑信息网-VulSee.com » [DelPHi] Delphi 进制转换——十六进制 to 十进制浮点数

评论 抢沙发

微慑信息网 专注工匠精神

微慑信息网-VulSee.com-关注前沿安全态势,聚合网络安全漏洞信息,分享安全文档案例

访问我们联系我们

觉得文章有用就打赏一下文章作者

非常感谢你的打赏,我们将继续提供更多优质内容,让我们一起创建更加美好的网络世界!

支付宝扫一扫打赏

微信扫一扫打赏

登录

找回密码

注册