sobota, 7 stycznia 2017

Binary numbers in Visual C++


#pragma endregion
private: System::Void write_Bits(System::Char x)
{
System::Int32 i;
System::Int32 temporary;
array <System::Char>^ date={1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192};
System::String^ text;
text="";
for(i=8;i>=0;i--)
{
temporary=(date[i]&x);
if(temporary!=0)
text=text+"1";
else
text=text+"0";
}
listBox2->Items->Add(text);
}
private: System::Void write_left_Bits(System::Char x)
{
System::Int32 i;
System::Int32 temporary;
array <System::Char>^ date={1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192};
System::String^ text;
text="";
for(i=8;i>=0;i--)
{
temporary=(date[i]&x);
if(temporary!=0)
text=text+"1";
else
text=text+"0";
}
listBox3->Items->Add(text);
}

   private: System::Void write_negation_Bits(System::Char x)
{
System::Int32 i;
System::Int32 temporary;
array <System::Char>^ date={1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192};
System::String^ text;
text="";
for(i=8;i>=0;i--)
{
temporary=(date[i]&x);
if(temporary!=0)
text=text+"1";
else
text=text+"0";
}
listBox4->Items->Add(text);
}

private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
Close();
}
private: System::Void button2_Click(System::Object^  sender, System::EventArgs^  e) {
;
System::Int32 i;
System::Int32 left;
System::Int32 negation;
for(i=0;i<32;i++)
{
listBox1->Items->Add(i.ToString());
write_Bits(i);
left=i<<1;
write_left_Bits(left);
negation=~i;
write_negation_Bits(negation);
 
}
 
}
private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {
}
};
}

Brak komentarzy:

Prześlij komentarz