--> | Delphi Tips Trick

For Newbie

Monday 26 September 2011

| Monday 26 September 2011
Binary to decimal and Hexa Decimal converter
            This application is used to change binary 8 bit data in to other forms that are decimal and hexadecimal. This application is used to make numeral binary conversion easier to be written in the Port Parallel that is impossible to write data in bit type format, the data that can be written to Port Parallel is Byte, Word, and DWord data.
To make binary numeral Converter Application to decimal and hexadecimal, enter the following component in the table to Form 1:

Table, the list of the Binary numeral Application Converter to the decimal and hexadecimal
No Component Properti Value
Form1 Caption BINER TO DEC AND HEXA
GroupBox1 Caption BINER
GroupBox1 Caption Hexa + Decimal
Label1 Caption D0
Label2 Caption D1
Label3 Caption D2
Label4 Caption D3
Label5 Caption D4
Label6 Caption D5
Label7 Caption D6
Label8 Caption D7
Label9 Caption Hexa
Label10 Caption Decimal
Edit1 Text 1
Edit2 Text 1
Edit3 Text 1
Edit4 Text 1
Edit5 Text 1
Edit6 Text 1
Edit7 Text 1
Edit8 Text 1
Edit9 Text Kosongkan
Edit10 Text Kosongkan
Button1 Caption Low
Button2 Caption Low
Button3 Caption Low
Button4 Caption Low
Button5 Caption Low
Button6 Caption Low
Button7 Caption Low
Button8 Caption Low
Button9 Caption CONVERT HEXA
Button10 Caption CONVERT DEC

After that arrange the visualization become:



Picture. Binary Converter Application Visualization Design to decimal and hexadecimal. 

After finishing arrange it, declare a global variable with value name integer type as the following picture below:

Picture; Global Variable declaration.
Type Source Code properly with the following table below:


Table. Binary numeral converter application visualization design to decimal and hexadecimal source code.


Component Event Source Code
Button1 OnClick value:=strtoint(edit1.Text);
if    value = 1 then
begin
value:=0;
button1.Caption:='High';
edit1.Text:=inttostr(value);
end
else
if value = 0 then
begin
value:=1;
edit1.Text:=inttostr(value);
button1.Caption:='Low';
end;
Button2 OnClick value:=strtoint(edit2.Text);
if    value = 1 then
begin
value:=0;
button2.Caption:='High';
edit2.Text:=inttostr(value);
end
else
if value = 0 then
begin
value:=1;
edit2.Text:=inttostr(value);
button2.Caption:='Low';
end;
Button3 OnClick value:=strtoint(edit3.Text);
if    value = 1 then
begin
value:=0;
button3.Caption:='High';
edit3.Text:=inttostr(value);
end
else
if value = 0 then
begin
value:=1;
edit3.Text:=inttostr(value);
button3.Caption:='Low';
end;
Button4 OnClick value:=strtoint(edit4.Text);
if    value = 1 then
begin
value:=0;
button4.Caption:='High';
edit4.Text:=inttostr(value);
end
else
if value = 0 then
begin
value:=1;
edit4.Text:=inttostr(value);
button4.Caption:='Low';
end;
Button5 OnClick value:=strtoint(edit5.Text);
if    value = 1 then
begin
value:=0;
button5.Caption:='High';
edit5.Text:=inttostr(value);
end
else
if value = 0 then
begin
value:=1;
edit5.Text:=inttostr(value);
button5.Caption:='Low';
end;
Button6 OnClick value:=strtoint(edit6.Text);
if    value = 1 then
begin
value:=0;
button6.Caption:='High';
edit6.Text:=inttostr(value);
end
else
if value = 0 then
begin
value:=1;
edit6.Text:=inttostr(value);
button6.Caption:='Low';
end;
Button7 OnClick value:=strtoint(edit7.Text);
if    value = 1 then
begin
value:=0;
button7.Caption:='High';
edit7.Text:=inttostr(value);
end
else
if value = 0 then
begin
value:=1;
edit7.Text:=inttostr(value);
button7.Caption:='Low';
end;
Button8 OnClick value:=strtoint(edit8.Text);
if    value = 1 then
begin
value:=0;
button8.Caption:='High';
edit8.Text:=inttostr(value);
end
else
if value = 0 then
begin
value:=1;
edit8.Text:=inttostr(value);
button8.Caption:='Low';
end;
Button9 OnClick var bit1,bit2,bit3,bit4,bit5,bit6,bit7,bit8,dec1,dec2,dec3,
dec4,dec5,dec6,dec7,dec8,dec_tot:integer;
begin
bit1:= strtoint(Edit1.text);
if bit1=0 then dec1:=0 else  dec1:=1;
bit2:= strtoint(Edit2.text);
if bit2=0 then dec2:=0 else dec2:=2;
bit3:= strtoint(Edit3.text);
if bit3=0 then dec3:=0 else   dec3:=4;
bit4:= strtoint(Edit4.text);
if bit4=0 then dec4:=0 else   dec4:=8;
bit5:= strtoint(Edit5.text);
if bit5=0 then dec5:=0 else   dec5:=16;
bit6:= strtoint(Edit6.text);
if bit6=0 then dec6:=0 else   dec6:=32;
bit7:= strtoint(Edit7.text);
if bit7=0 then dec7:=0 else   dec7:=64;
bit8:= strtoint(Edit8.text);
if bit8=0 then dec8:=0 else   dec8:=128;
dec_tot:=dec1+dec2+dec3+dec4+dec5+dec6+dec7+dec8;
edit10.Text:=inttostr(dec_tot);
Button10 OnClick var str1,str2,hexa : string;
begin
str1 :=Edit4.Text + Edit3.Text + Edit2.Text + Edit1.Text;
   if (str1 = '0000')then hexa :='0';
if (str1 = '0001')then hexa :='1';
if (str1 = '0010')then hexa :='2';
if (str1 = '0011')then hexa :='3';
if (str1 = '0100')then hexa :='4';
if (str1 = '0101')then hexa :='5';
if (str1 = '0110')then hexa :='6';
if (str1 = '0111')then hexa :='7';
if (str1 = '1000')then hexa :='8';
if (str1 = '1001')then hexa :='9';
if (str1 = '1010')then hexa :='A';
if (str1 = '1011')then hexa :='B';
if (str1 = '1100')then hexa :='C';
if (str1 = '1101')then hexa :='D';
if (str1 = '1110')then hexa :='E';
if (str1 = '1111')then hexa :='F';
str2 := Edit8.Text + Edit7.Text + Edit6.Text +  Edit5.Text ;
if (str2 = '0000')then hexa :='0'+hexa;
if (str2 = '0001')then hexa :='1'+hexa;
if (str2 = '0010')then hexa :='2'+hexa;
if (str2 = '0011')then hexa :='3'+hexa;
if (str2 = '0100')then hexa :='4'+hexa;
if (str2 = '0101')then hexa :='5'+hexa;
if (str2 = '0110')then hexa :='6'+hexa;
if (str2 = '0111')then hexa :='7'+hexa;
if (str2 = '1000')then hexa :='8'+hexa;
if (str2 = '1001')then hexa :='9'+hexa;
if (str2 = '1010')then hexa :='A'+hexa;
if (str2 = '1011')then hexa :='B'+hexa;
if (str2 = '1100')then hexa :='C'+hexa;
if (str2 = '1101')then hexa :='D'+hexa;
if (str2 = '1110')then hexa :='E'+hexa;
if (str2 = '1111')then hexa :='F'+hexa;
Edit9.text :=hexa;
end;



After that run, the following is the testing visualization of binary to hexa decimal and decimal Converter Application visualization design to decimal and hexadecimal that is made:




  I hope this article can give benefit to the visitors, readers, developer and me. Thanks for visiting and availability for sharing this article by pressing 
Share this on Facebook
or just press like button under this posting

Related Posts