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 合并字符串的函数

Delphi 如何快速读写文件中的字符串

Delphi downloadtomemory

Delphi http协议验证访问datasnap rest 服务器

Delphi shgetfileinfo函数获取任何文件大图标

Delphi firedac操作sqlite内存数据库

Delphi clientdataset 与fdmemtable 创建 字段与追加记录

Delphi 正则表达式起步

Delphi 数据类型cardinal 怎么转换成 string?

Delphi读取xml文件

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



打赏

取消

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

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

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

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

评论

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