cantfindunusedname

I am trying to load a byte variable with data that is collected from RadioButtons.
For instance:
Bit 0 would be set or not depending on the coresponding RadioButton.
Bit 1 would be set or not depending on the coresponding RadioButton.
.
.
Bit 7

The question is, how do I set the Bit values I already have all the RadioButtons setting boolean variables. I just need to get those variables in to the corresponding Bit value so that I can send that byte out the SerialPort for a microcontroller to read.

Thanks again for your help in advance,
Steve


Re: Visual C# Language Byte

cantfindunusedname

I figured out the answer to my question so I will delete the post.




Re: Visual C# Language Byte

Gregor Berginc

Steve,

this might help

Code Snippet


byte bits = 0;


// For i-th bit, use the corresponding RB value

if (rd.Checked)

{

// Shift 1 for i number of times to the left.

bits |= (1 << i);

} // if



It's best if your radio buttons are stored in an array, so you can simply use a loop to set the bits accordingly.

HTH,
Gregor