Question

I have several UINT8_T values and I may be confused here but can I use their values as a conditional statement in objective C? so if I have 00000001 then bool digitalOutput1 should be set to true?

Sorry if this is unclear... Please feel free to ask for any clarification.

How I traverse the UINT8_T object is as such:

  uint8_t value = input.value; //This is a value from an outside source
  for(UISwitch *temp in switchArrayIn){
    temp.on = (value & 1)
    value >>= 1;
}

so I am shifting down each bit to check if each value has a 1 or a 0, and if it does have a 1 - turn on a switch output; if it does not - turn it off.

Basically what I am asking is if I am traversing a UINT8_T variable/instance that has a value assigned to it, whatever that may be. Can I use it as a conditional statement in comparison to boolean values? i.e.;

 bool test = TRUE;
    uint8_t = 00000001;
   for(int i = 0; i<7; i++){
    if(test == (value & i)){
   // do something
}
Was it helpful?

Solution

You can use absolutely any scalar in a Boolean context in C. A value of 0 (which is representable by all scalar types) is treated as false, and any other value is treated as true.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top