#### Archived

This topic is now archived and is closed to further replies.

# enum and bit operators

This topic is 5550 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I''m having the weirdest problem with trying to flip a bit in a byte and then send the byte out the serial port... I know my serial communication is working ok, and I know the checksum is working ok, so I''m reasonably sure that the failure to flip the bit is in the code on my PC. Here''s my code:
// vars that aren''t defined in this snippet...

bool Enabled;
enum CommandFlag {CF_ENABLE = 0x08};
BYTE Command;

if (Enabled)
Command |= CF_ENABLE;
else
Command &= ~CF_ENABLE;

So, if everything was right with the world, it would set bit 3 of the Command byte high or low depending on if Enabled is true or false, right? Somehow it doesn''t work. I''m wondering if maybe it has something to do with enum being an int and Command being a byte? Any thoughts? This one''s had me stumped for more than a week... --------------------

You are not a real programmer until you end all your sentences with semicolons; (c) 2000 ROAD Programming
You are unique. Just like everybody else.
"Mechanical engineers design weapons; civil engineers design targets."
"Sensitivity is adjustable, so you can set it to detect elephants and other small creatures." -- Product Description for a vibration sensor

##### Share on other sites
try replacing CF_ENABLE with the magic number 8 in your code. if it works like that, then you know what the problem is, don't you?

[edited by - foofightr on August 11, 2003 1:16:08 PM]

##### Share on other sites
This code will clear or set bit 3 (assuming the LSB is bit 0) depending on whether Enabled is zero or not-zero. If that is what you want, then I doubt the problem is here.

When you step through the code in the debugger, when does the value become incorrect?

##### Share on other sites
The debugger is useless for me in this situation, unfortunately There is an indeterminate number of cycles where this is called before Enabled is set to true (due to a client program connecting via winsock), so stepping through it cycle by cycle with a breakpoint isn''t feasible. My client connection would time out before it even got to my questionable code. I''ve tried setting a conditional breakpoint, but the condition is never triggered... perhaps I set it wrong.

--------------------

You are not a real programmer until you end all your sentences with semicolons; (c) 2000 ROAD Programming

You are unique. Just like everybody else.

"Mechanical engineers design weapons; civil engineers design targets."
"Sensitivity is adjustable, so you can set it to detect elephants and other small creatures." -- Product Description for a vibration sensor

##### Share on other sites
That has to be the number one flipping method:

Command ^= CF_ENABLE;

// Parzec

##### Share on other sites
If you can''t use the debugger, then fall back on screen/file output.

1. 1
Rutin
46
2. 2
3. 3
4. 4
5. 5

• 13
• 10
• 12
• 10
• 13
• ### Forum Statistics

• Total Topics
632993
• Total Posts
3009763
• ### Who's Online (See full list)

There are no registered users currently online

×