Delphi 超短精简进制转换


本文整理自网络,侵删。

 //十六进制(S)-->>十进制(I) [重写:Jey]
function hextoint(s: string): Integer;
begin //$代表16进制
Result:=StrToInt('$'+s);
end;

//十进制转换为二进制字符串 [重写:Jey]
function inttoBin(i: integer): string;
begin
while i <>0 do
begin //i mod 2取模,再使用format格式化
result:=Format('%d'+result,[i mod 2]);
i:=i div 2
end
end;

//二进制(S)-->>十进制(D) [重写:Jey]
uses Math;
function hextoint(s: string): Double;
begin
while Length(s) <>0 do
begin //2^(长度-1)次方
if s[1]='1' then Result:=Result+power(2,Length(s)-1);
s:=Copy(s,2,Length(s));
end
end;

//十进制(I)-->>十六进制(S)
//D自带函数,Digits长度,一般设4.
function IntToHex(Value: Integer; Digits: Integer): string;

//数据(S)-->>二进制(S)
//任何数据都是以二进制形式存储的! (转)
function conertde(s:string):string;
var
i:integer;
begin
for i:=1 to length(s) do
result:=result+inttohex(ord(s[i]),2);
end;

相关阅读 >>

Delphi fmx检查应用程序状态更改

Delphi exe执行程序dos参数的运用

Delphi 提高unigui开发效率的两个方法

Delphi2010显示选择文件夹对话框 (有新建按钮)

Delphi xe10.1 andriod app中文名称

Delphi memo控件对粘贴板的支持

Delphi sql语句查询最新的各个台位的最后一个检测值

Delphi中使用ado连接带密码的access

Delphi 将dbgrid的数据导出到excel文件保存

Delphi 10.3.1新的变量的声明方法

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...