I was going through part of a PIC code i downloaded using the CCS compiler, plz can someone explain to me the meaning of " if (s & 8)" , s was declared as an integer, plz i would be anticipating help soonest, thanks in advance.
Re: meaning of this ccs code http: if(s&8) OUTPUT_HIGH(PIN_A3); else OUPUT_HIGH(PI
Hello Mr FoxyRick, thanks a lot, plz can you show me any link where this issue was handled, coz i'm still not clear with the roll of the '8' used in the code and not bit '3' as u said, also i've gone through CCS programming manual
and still could not find any similar example . once more thanks a lot
Re: meaning of this ccs code http: if(s&8) OUTPUT_HIGH(PIN_A3); else OUPUT_HIGH(PI
You may not find this in CCS programming manual. This is just C code. Search the internet for Bitwise operations in C.
8 in binary is equal to 00001000. So it is the bit 3 which is one and all other bits are zero. When this 8 (00001000) is bitwise AND (&) with any number.The result will be zero (False) except for the numbers which has its bit # 3 is set (high).
In other words, this operation is basically testing the variable s for bit #3 for high (1). If true, the output A3 is High for 1ms otherwise A2 is high for 1ms.
Re: meaning of this ccs code http: if(s&8) OUTPUT_HIGH(PIN_A3); else OUPUT_HIGH(PI
Code:
if(s&8)
in this, assume a switch is connected to 3rd bit of the PORT.
By this condition we are checking, whether the switch is pressed or not.
If the switch is pressed, s becomes 0001000 and binary value of 8 is 00001000. Bitwise AND(&) operation of these two numbers will true ,then PIN_A3 will be high, otherwise the value becomes false and the PINA_3 will be LOW.