unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;type TForm1 = class(TForm) Label1: TLabel; Label2: TLabel; Label3: TLabel; procedure FormCreate(Sender: TObject); private { Private declarations } public end;var Form1: TForm1;implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject); var E: Extended; //Make sure there is room for null terminator Buf: array[0..SizeOf(Extended) * 2] of Char; begin E := Pi; Label1.Caption := Format('Pi starts off as %.15f', [E]); BinToHex(@E, Buf, SizeOf(E)); //Slot in the null terminator for the PChar, so we can display it easily Buf[SizeOf(Buf) - 1] := #0; Label2.Caption := Format('As text, the binary contents of Pi look like %s', [Buf]); //Translate just the characters, not the null terminator HexToBin(Buf, @E, SizeOf(Buf) - 1); Label3.Caption := Format('Back from text to binary, Pi is now %.15f', [E]); end;end.
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
var
E: Extended;
//Make sure there is room for null terminator
Buf: array[0..SizeOf(Extended) * 2] of Char;
begin
E := Pi;
Label1.Caption := Format('Pi starts off as %.15f', [E]);
BinToHex(@E, Buf, SizeOf(E));
//Slot in the null terminator for the PChar, so we can display it easily
Buf[SizeOf(Buf) - 1] := #0;
Label2.Caption := Format('As text, the binary contents of Pi look like %s', [Buf]);
//Translate just the characters, not the null terminator
HexToBin(Buf, @E, SizeOf(Buf) - 1);
Label3.Caption := Format('Back from text to binary, Pi is now %.15f', [E]);
end;end.
我是想用一个edit1来输入一个二进制数据,原来在edit2里显示出十六进制