I am reading the code that involves some bitwise operations as shown below:
unsigned char data = 0;
unsigned char status = 0;
//DAQmx functions for reading data
DAQmxReadDigitalLines(taskHandleIn,1,10.0,DAQmx_Val_GroupByChannel,dataIn,8,&read,&bytesPerSamp,NULL);
DAQmxReadDigitalLines(taskHandleOut,1,10.0,DAQmx_Val_GroupByChannel,dataOutRead,8,&read,&bytesPerSamp,NULL);
for (int i = 0; i < 8; i++)
{
if (dataOutRead[i] == 1)
data = data | (0x01 << i);
else
data = data & ~(0x01 << i);
}
for (int i = 0; i < 4; i++)
{
if (dataIn[i] == 1)
status = status | (0x01 << (7 - i));
else
status = status & ~(0x01 << (7 - i));
}
ctrl = 0;
In the above codes, dataOutRead
and dataIn
are both uInt8
8-element arrays originally initialized to zero.
I don't quite understand what the code is actually doing? Anyone can walk me through these codes?