//=========================================================================== // ASCII to Decimal to Byte Conversions //=========================================================================== #include #pragma hdrstop #include "Unit1.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- //=========================================================================== // VARIBALES //=========================================================================== BYTE myByte; //=========================================================================== // FUNCTIONS //=========================================================================== void ASCIIToBits (void) { char* asciiText = new char[ Form1->EditASCII->Text.Length() + 1 ]; strcpy( asciiText, Form1->EditASCII->Text.c_str() ); myByte = asciiText[0]; if ((myByte & 0x01) == 0x01) Form1->Edit1->Text = 1; else Form1->Edit1->Text = 0; if ((myByte & 0x02) == 0x02) Form1->Edit2->Text = 1; else Form1->Edit2->Text = 0; if ((myByte & 0x04) == 0x04) Form1->Edit3->Text = 1; else Form1->Edit3->Text = 0; if ((myByte & 0x08) == 0x08) Form1->Edit4->Text = 1; else Form1->Edit4->Text = 0; if ((myByte & 0x10) == 0x10) Form1->Edit5->Text = 1; else Form1->Edit5->Text = 0; if ((myByte & 0x20) == 0x20) Form1->Edit6->Text = 1; else Form1->Edit6->Text = 0; if ((myByte & 0x40) == 0x40) Form1->Edit7->Text = 1; else Form1->Edit7->Text = 0; if ((myByte & 0x80) == 0x80) Form1->Edit8->Text = 1; else Form1->Edit8->Text = 0; Form1->EditDecimal->Text = myByte; // gives decimal } void BitsToASCII (void) { char* asciiText = new char[2]; if (Form1->Edit1->Text == 1) myByte |= 0x01; else myByte &= ~0x01; if (Form1->Edit2->Text == 1) myByte |= 0x02 ; else myByte &= ~0x02; if (Form1->Edit3->Text == 1) myByte |= 0x04 ; else myByte &= ~0x04; if (Form1->Edit4->Text == 1) myByte |= 0x08 ; else myByte &= ~0x08; if (Form1->Edit5->Text == 1) myByte |= 0x10 ; else myByte &= ~0x10; if (Form1->Edit6->Text == 1) myByte |= 0x20 ; else myByte &= ~0x20; if (Form1->Edit7->Text == 1) myByte |= 0x40 ; else myByte &= ~0x40; if (Form1->Edit8->Text == 1) myByte |= 0x80 ; else myByte &= ~0x80; asciiText[0] = myByte; Form1->EditASCII->Text = asciiText[0]; // gives character Form1->EditDecimal->Text = myByte; // gives decimal } //=========================================================================== // EVENT HANDLERS //=========================================================================== void __fastcall TForm1::ButtonASCIIToBitsClick(TObject *Sender) { ASCIIToBits(); } //--------------------------------------------------------------------------- void __fastcall TForm1::ButtonBitsToASCIIClick(TObject *Sender) { BitsToASCII(); } //---------------------------------------------------------------------------