Component | Properties | Keterangan |
2 Tbutton | Caption:Integer To Binary dan Binary To Integer | |
2 TEdit | Name:edNilaiInteger dan edNilaiBinary | |
2 TLabel | Name:lblNilaInteger dan lblNilaiBiner |
function BinToInt(value:String):integer; var i , nilaUkuran:Integer; begin Result:=0; nilaUkuran:=Length(value); for i := nilaUkuran downto 1 do begin if value[i]='1' then Result:=Result + (1 shl(nilaUkuran-i)); end; end;
function IntToBin(value:Longint;Nilai:integer):String; var i :Integer; begin Result:=''; for i := Nilai downto 0 do begin if value and (1 shl i) <> 0 then begin Result := Result+'1'; end else begin Result:=Result+'0'; end; end; end;
procedure TForm1.Button1Click(Sender: TObject); begin if (edNilaiInteger.Text<>'') then begin lblNilaiBiner.Caption:=IntToBin(StrToInt(edNilaiInteger.Text),7) end; end;
procedure TForm1.Button2Click(Sender: TObject); begin if edNilaiBinary.Text<> '' then begin lblNilaInteger.Caption:=IntToStr(BinToInt(edNilaiBinary.Text)); end; end;
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) edNilaiInteger: TEdit; Button1: TButton; lblNilaiBiner: TLabel; Button2: TButton; edNilaiBinary: TEdit; lblNilaInteger: TLabel; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} function BinToInt(value:String):integer; var i , nilaUkuran:Integer; begin Result:=0; nilaUkuran:=Length(value); for i := nilaUkuran downto 1 do begin if value[i]='1' then Result:=Result + (1 shl(nilaUkuran-i)); end; end; function IntToBin(value:Longint;Nilai:integer):String; var i :Integer; begin Result:=''; for i := Nilai downto 0 do begin if value and (1 shl i) <> 0 then begin Result := Result+'1'; end else begin Result:=Result+'0'; end; end; end; procedure TForm1.Button1Click(Sender: TObject); begin if (edNilaiInteger.Text<>'') then begin lblNilaiBiner.Caption:=IntToBin(StrToInt(edNilaiInteger.Text),7) end; end; procedure TForm1.Button2Click(Sender: TObject); begin if edNilaiBinary.Text<> '' then begin lblNilaInteger.Caption:=IntToStr(BinToInt(edNilaiBinary.Text)); end; end; end.
Untuk mengecek apakah valid bilangan biner tersebut , silahkan lihat disini Sekian untuk tutorial kali ini , semoga bermanfaat :)
6 komentar:
Gan boleh minta template nya seperti agan ga'.......?????????????
kalau boleh tolong kirimkan donk ke email : falahmulyana@gmail.com
Atas saran dari sahabat muhammad iqbal, saya berkunjung ke sini. Ternyata memang materinya sudah bagus. Saya izin belajar mas
makasih banyak atas semua info dan saran nya ,,,,,
susah amat bang...di delphi juga sudah ada fungsi bawaannya...
Keren nih ijin praktek sob
ass wr wb. saya noll dalam masalah ini. boleh kah saya belajar ke pada bapak.
Posting Komentar