Delphi 二进制值转换十六进制 BinToHex和HexToBin


本文整理自网络,侵删。

 

//本示例的目的是说明Classes单元中的BinToHex和HexToBin方法。此代码会将二进制值转换为其十六进制表示形式并返回。

procedure Tfrm1.btnToStringClick(Sender: TObject);

var
  LStr1, LStr2: WideString;

begin
  { Store the text in the memo to a String variable. }
  LStr1 := Memo2.Lines.Text;
  { Set the length of the String to hold the conversion. }
  SetLength(LStr2, Length(LStr1) div 4);
  { Call the hexadecimal to binary conversion procedure. }
  HexToBin(PWideChar(LStr1), LStr2[1], Length(LStr1) div SizeOf(Char));
  { Output the results to Memo1. }
  Memo1.Lines.Text := LStr2;
end;

procedure Tfrm1.btToHexClick(Sender: TObject);
var
  LStr1, LStr2: String;

  begin
  { Store the text in the memo to a String variable. }
  LStr1 := Memo1.Lines.Text;
  { Set the length of the String to hold the conversion. }
  SetLength(LStr2, Length(LStr1) * 4);
  { Call the binary to hexadecimal conversion procedure. }
  BinToHex(LStr1[1], PWideChar(LStr2), Length(LStr1) * SizeOf(Char));
  { Put the results in Memo2. }
  Memo2.Lines.Text := LStr2;
end;

相关阅读 >>

Delphi 比较完整的listview1用法

Delphi tfdquery提交tfdmemtable修改的数据

Delphi循环遍历同类控件或所有控件

Delphi tapplication大全

Delphi中实现变长函数笔记

Delphi获得webbrowser中的html文本

Delphi应用程序 paramstr()带有参数

Delphi memo1 光标跟随鼠标移动

Delphi firedac 连接access mdb数据库的方法

Delphi xe5 android应用程序获取电池信息

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



打赏

取消

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

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

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

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

评论

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

    暂无评论...