I am not quite understanding why the program described at Question11-1 from (Page 169) is working - I am expecting it not to work. Might somebody please explain why.
The result should 0 after masking after masking the bits in the line 'if ((flags & DIRECT_CONNECT) != 0)', right?
--- output of program ---
High speed set
Direct connect set
---- snip -----
const int HIGH_SPEED = (1<<7); /* modem is running fast */
// we are using a hardwired connection
const int DIRECT_CONNECT = (1<<8);
char flags = 0;
flags |= HIGH_SPEED; // we are running fast
flags |= DIRECT_CONNECT; // because we are wired together
if ((flags & HIGH_SPEED) != 0)
std::cout << "High speed set\n";
if ((flags & DIRECT_CONNECT) != 0)
std::cout << "Direct connect set\n";