Code question
Don M
Posts: 1,653
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
I'd use constants for $0108 and $010F.
It 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...
Sorry, 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.