Am making a Binary converter in a windows form using Get and Set method
Code to carry out the conversion
class SubnetConvert
{
private int numconvert;
private string OctetToBinary;
public int OctetConvert
{
get
{
return numconvert;
}
set
{
List<int> Subnet = new List<int>(new int[] { 128, 64, 32, 16, 8, 4, 2, 1 });
foreach (int num in Subnet)
{
if (num <= numconvert)
{
numconvert -= num;
OctetToBinary += "1";
}
else
{
OctetToBinary += "0";
}
}
}
}
public string SendBinary
{
set
{
OctetToBinary = value;
}
get
{
return OctetToBinary;
}
}
Code applied to the Convert button
private void btnSubnetting_Click(object sender, EventArgs e)
{
SubnetConvert SubnetOctet = new SubnetConvert();
lblOctet1.Text = "";
int Octet1 = int.Parse(txtOctet1.Text);
SubnetOctet.OctetConvert = Octet1;
lblOctet1.Text = SubnetOctet.SendBinary;
}
At the moment the only value returned is either 8 0s or 8 1s
Before this line:
add this line: