enum and bit operators

Started by
4 comments, last by Yanroy 20 years, 8 months ago
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

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

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

Advertisement
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]
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?
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!
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

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

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

How about trying XOR?
That has to be the number one flipping method:

Command ^= CF_ENABLE;


// Parzec
// Parzec
If you can''t use the debugger, then fall back on screen/file output.

This topic is closed to new replies.

Advertisement