czwartek, 22 sierpnia 2024

Negation and bit shift - C++ Builder


 

void __fastcall TForm1::write_Bits(char x, TListBox *Tl)

{

 unsigned char date[11]={1,2,4,8,16,32,64,128,256,512,1024};

 UnicodeString result;

 int i,y;

 result="";

 for(i=10;i>=0;i--)

 {

  y=(date[i] & x);

  if(y!=0)

   result+="1";

  else

   result+="0";

 }

 Tl->Items->Add(result);


}

//---------------------------------------------------------------------------

void __fastcall TForm1::Button2Click(TObject *Sender)

{

 Close();

}

//---------------------------------------------------------------------------

void __fastcall TForm1::Button1Click(TObject *Sender)

{

 int a1,a2,a3,i;

 for(i=0;i<128;i++)

 {

a1=i;

a2=~a1;

a3=a1<<1;

write_Bits(a1,ListBox1);

write_Bits(a2,ListBox2);

write_Bits(a3,ListBox3);

 }

}

Brak komentarzy:

Prześlij komentarz