This is a discussion on bitwise operator within the C Programming forums, part of the General Programming Boards category; Self Deleted......
Last edited by donkey_C; 09-26-2010 at 11:55 AM. Reason: Since no one answered i guess my phrasing was not good so deleting
Then a "mask" can be created to test the temp byte. Remember, "or" turns bits on and
"and" turns bits off when the mask is set up properly. A brute force method (I'm assuming you're new at C) would be to create 8 masks to test each bit position. Set up a loop to test the result of each of the 8 mask operations. When you get some code and it works, try
to pulling it out of main() and into its own function.
EDIT: Clarification - Use the mask to turn off the bits not being tested, then read the variable to check if the
bit was on or off.
Edit#2: 8 masks is a bit too much "brute force" for me, but I suggested it that way to give you a clear understanding. A better
way would be to have ONE mask, and then increment the bit being tested i.e change it to test for byte values 1, 2, 4, etc.
Last edited by Char*Pntr; 09-26-2010 at 12:44 PM. Reason: my usual typos
and not stuff like this.
While I'm at it, I'd like to announce to the world that I'm now reading
K/R The C Programming Language, 2nd addition!
No longer torture this board with questions because of misinformation from
the "learn C 21 Days"....
but in my situation the variable X is not in my control. it keeps on changing. so i need to keep monitoring it. any one bit or all the bits may go high (1) every one millisecond. so do i have to write like this say for bit 1 mask off and check variable? bit 2 do the same bit 3 do the same... or am i getting it all wrong
Thanks for helping out
for the bit position being tested for. Sorry, I'm still waking up!
First you have to write some code, using code tags. Here is a useful link
on the FAQ here: Cprogramming.com FAQ
Check out the "How do I...?" links
sorry had got logged off My battery died