Code question
Lets say I'm parsing through some word size data. The data falls within these ranges:
0108 - 010F
0110 - 0117
0130 - 0137
To look at all data, as I'm doing now I use this statement:
My question is how do I structure my if statment to look for just any one or combination of the ranges I mentioned above?
Thanks.
Don
0108 - 010F
0110 - 0117
0130 - 0137
To look at all data, as I'm doing now I use this statement:
if (data & $0100) == $0100 something happens
My question is how do I structure my if statment to look for just any one or combination of the ranges I mentioned above?
Thanks.
Don

Comments
if(data => $0108 AND data =< $010F) 'do somethingI'd use constants for $0108 and $010F.
PUB Main : result | PWLevel ctra[30..26] := %01000 ' "POS detector" ctra[5..0] := 6 frqa := 1 dira[6] := outa[6] := 1 waitcnt(clkfreq/100_000 + cnt) ' Wait for circuit to charge phsa~ dira[6]~ ' Pin to input starts measurement waitcnt(clkfreq/60 + cnt) ' Seems to be enough time to get value PWLevel := (phsa - 624) #> 0 [B]Case [/B] PWLevel 0..3210 : PWLevel := 0 3211..6420 : PWLevel := 1 6421..9630 : PWLevel := 2 9631..12840 : PWLevel := 3 12841..16050 : PWLevel := 4 16051..19260 : PWLevel := 5 19261..22470 : PWLevel := 6 22471..25680 : PWLevel := 7 25681..28890 : PWLevel := 8 28891..32100 : PWLevel := 9 32101..35310 : PWLevel := 10 35311..38520 : PWLevel := 11 38521..41730 : PWLevel := 12 41731..44940 : PWLevel := 13 44941..48150 : PWLevel := 14 48151..51360 : PWLevel := 15 51361..54570 : PWLevel := 16 54571..57780 : PWLevel := 17 57781..60990 : PWLevel := 18 60991..64200 : PWLevel := 19 result := PWLevelIt looks like this would work
For all but a few extremes of your ranges.
@Mike- that was what I was looking for and it works. Thanks.
Here's is what I came up with. It works and if there are suggestions to make it cleaner and simpler I'm all ears...
con A1 = $0108 A2 = $010F B1 = $0110 B2 = $0117 C1 = $0130 C2 = $0137 pub case mode $0: data1 := A1 data2 := C2 $1: data1 := A1 data2 := A2 $2: data1 := C1 data2 := C2 $3: data1 := B1 data2 := B2 if(data => data1 AND d =< data2) do somethingDAT minval word A1, A1, C1, B1 maxval word C2, A2, C2, B2 PUB ... ... if( data => minval[ mode ] and data =< maxval[ mode ] do somethingSorry, I forgot this was Don's thread. You were just giving an example of case.
The "/=" is used when the result is part of the equation. Say you want to x to equal x divided by 2 you could use:
or even shorter:
I just thought your data in your case statement looked like a linear relationship. It's always nice when one can find practical applications for math.
Sorry for the detour Don.
Thanks. I like the simplicity. Works well.