Archived

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

Yanroy

enum and bit operators

Recommended Posts

Yanroy    122
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

Yanroy@usa.com

Share this post


Link to post
Share on other sites
foofightr    130
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 this post


Link to post
Share on other sites
JohnBolton    1372
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 this post


Link to post
Share on other sites
Yanroy    122
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

Yanroy@usa.com

Share this post


Link to post
Share on other sites