Exact match. Not showing close matches.
'[PIC] Re: newbie question - basic logic and a/d co'
Sean C. Malloy
|> The following code works
> if(adc_result<0x0F) //if a/d count is below F then
> if(0x0F<=adc_result) //if a/d count is above or equal to F then
> but this code does not
> if(0x00<=adc_result<0x0F) //if a/d is below F then
> if(0x0F<=adc_result<=0xFF) //if a/d is below F then
> I'm sure I am overlooking something simple
Since I read this list as a digest, I wouldn't be suprised if someone else
has already answered, but...
In C, the syntax "if ( adc_result < 0x0F )" is valid, while "if ( 0x0F <=
adc_result <= 0xFF )" is not.
A variable can only be compared to a single value, but you may make compound
statements using logical operators ( && for AND and || for OR )
The valid syntax for what you're trying to write would be:
if ( (adc_result >= 0x0F) && (adc_result <= 0xFF) )
Note that it's "&&" and not "&". Picking up a copy of "The C Programming
Language" by K&R is a great idea if you're trying to learn C syntax.
Sean C. Malloy io.comsmalloy
> In C, the syntax "if ( adc_result < 0x0F )" is valid, while "if ( 0x0F <=
> adc_result <= 0xFF )" is not.
Ah ha.. Learn somethin new everyday.. So thats why whenever I tried to
write(I've been coding in C/C++ for about 8 years)
if(x=somefunc() != 0)
That it didnt work.. Figures its some syntax of C.
It would work if you did this instead:
if((x=somefunc()) != 0)
On 1/18/06, andrew kelley <gmail.com> wrote: leetslacker
More... (looser matching)
- Last day of these posts
- In 2006
, 2007 only
- New search...