Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Converting from integer Value to Boolean Array - DAQmx

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

0 Kudos
Message 1 of 2
(6,432 Views)

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]);

Ben

National Instruments
Certified LabVIEW Associate Developer
Certified TestStand Developer
0 Kudos
Message 2 of 2
(6,408 Views)