I'm going to assume that in addition to setting the 'Checked property of the CheckBoxes based on a byte value ... as Karthik neatly shows you how to do, that you also want to read the CheckBoxes' checked state, and construct a byte value.
private List<checkbox> cbList = new List<checkbox>();
cbList.AddRange(new CheckBox[]
{
checkBox1, checkBox2, checkBox3, checkBox4, checkBox5, checkBox6, checkBox7, checkBox8
});
private byte getByteFromCheckBoxes()
{
byte b = 0x0;
for (int i = 0; i < 8; i++)
{
if(cbList[i].Checked) b += Convert.ToByte(Math.Pow(2, i));
}
return b;
}
private void button1_Click(object sender, EventArgs e)
{
byte checkByte = getByteFromCheckBoxes();
}
For eliminating the computation in the function above ... which I'd want to do if generating a byte from the CheckBoxes was occurring frequently ... I'd consider using a Dictionary:
private Dictionary<CheckBox, byte> dctChkByte;
dctChkByte = new Dictionary<checkbox,>
{
{checkBox1, 0x01},
{checkBox2, 0x02},
{checkBox3, 0x04},
{checkBox4, 0x08},
{checkBox5, 0x10},
{checkBox6, 0x20},
{checkBox7, 0x40},
{checkBox8, 0x80},
};
private byte getByteFromCheckBoxes2()
{
byte b2 = 0x0;
foreach (CheckBox theCheckBox in dctChkByte.Keys)
{
if (theCheckBox.Checked) b2 += dctChkByte[theCheckBox];
}
return b2;
}