05-27-2009 02:06 PM
Using the below NI example - I am writing to a port and want to convert fom an int value and convert it to a Boolean array format - i.e excepting input from from a user ( i.e 255) will populate the array with 11111111.
digitalWriteTask.DOChannels.CreateChannel(channelParametersTextBox.Text,"",
ChannelLineGrouping.OneChannelForAllLines);
bool[] dataArray = new bool[8];
dataArray[0] = bit0CheckBox.Checked;
dataArray[1] = bit1CheckBox.Checked;
dataArray[2] = bit2CheckBox.Checked;
dataArray[3] = bit3CheckBox.Checked;
dataArray[4] = bit4CheckBox.Checked;
dataArray[5] = bit5CheckBox.Checked;
dataArray[6] = bit6CheckBox.Checked;
dataArray[7] = bit7CheckBox.Checked;
Thanks
Joe
05-28-2009 05:40 PM
From what I understand, you are asking for C# code on how to convert from an integer to a boolean array. Is this correct?
If so, I believe the code below will accomplish this:
int input;
string output = Convert.ToString(input, 2);bool[] myArray;myArray =
new bool[output.Length];for (int i = 0; i < output.Length; i++)
myArray[i] = Convert.ToBoolean(output[i]);