In this example, we are going to create a program that can convert an eight binary data into an integer value using BinaryToInteger.DLL. Before we start, you have to create a user interface like this picture.
Every edit box holds a bit of binary data. So there is a byte binary data (8 bits) that will be converted into an integer value. A binary data holds ‘0’ or ‘1’, so we need to limit the input of each edit box. And the code will be :
procedure TForm1.bit8KeyPress(Sender: TObject; var Key: Char);
begin
if not (key in ['0','1',#8,#13]) then
key:=#0
else
bit7.SetFocus;
end;
To use BinaryToInteger.DLL, you must declare the function after {$R *.DFM}
{$R *.DFM}
function BinToInt(S : String): integer; stdcall; external 'BinaryToInteger.dll';
Don forget, you must place your BinaryToInteger.DLL in the same folder with this project, or you can place this DLL file in the directory : c:\windows\system.
The code of OnClick even of ConvertButton :
procedure TForm1.ConvertButtonClick(Sender: TObject);
var
BinaryData : string;
begin
BinaryData := bit8.Text + bit7.Text + bit6.Text + bit5.Text +
b it4.Text + bit3.Text + bit2.Text + bit1.Text;
IntegerValue.Caption := IntToStr(BinToInt(BinaryData));
end;
You can download the complete code of this example program here.
wah, sumpah gak ngerti ...
ReplyDeletepakde mampir lagi untuk menimba ilmu, boleh donk
ReplyDeletemoga sukses selalu kawan
code2 seperti ini softwarenya pakai apa yah sob ?
ReplyDeletejika benrkenan follow balik yah ?
ReplyDeletebaru lihat codenya aja dah ngelu pol sob
ReplyDeletesaya menyimak aja Sob, soalnya belum ngerti...
ReplyDeletesukses Sob...