Thread: Testing ~bit

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Dec 2005
    Posts
    54

    Testing ~bit

    I am a little confused on how to test user input with the correct answer of a complementary bit. A labby told us just to AND it with 255, but I do not understand why we are doing that.

    byte1 is an randomly generated unsigned char from 0 - 255
    userInput is an intiger

    Code:
    // Asks for answer of ~byte1
    	con << "What is the COMPLEMENT result of " << int(byte1) << " ("; toBin(byte1); con << ")?\n";
    	con << "> ";
    	if(!(cin >> userInput))
    	{
    		cin.clear();
    		cin.ignore(20, '\n');
    		con << "Bad Input! Incorrect Answer.\n";
    	}
    	else 
    	{
    		// Checks to see if the answer is correct
    		if (userInput == (~byte1 & 255))
    		{
    			numCorrect++;
    			con << "Correct!\n";
    		}
    		else
    			con << "False!\n";
    
    		cin.ignore(20, '\n');
    	}
    Last edited by JeremyCAFE; 01-05-2006 at 08:26 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 64 bit testing
    By DrSnuggles in forum C++ Programming
    Replies: 7
    Last Post: 11-20-2007, 03:20 AM
  2. C++ bit testing
    By Vicious in forum C++ Programming
    Replies: 3
    Last Post: 09-19-2004, 11:44 AM
  3. Blending and Depth Testing
    By Thunderco in forum Game Programming
    Replies: 2
    Last Post: 03-08-2004, 06:37 PM
  4. about testing a program
    By Abdi in forum C Programming
    Replies: 1
    Last Post: 06-09-2002, 12:51 AM
  5. Testing Testing 123.. Oh yeah and...
    By minime6696 in forum Windows Programming
    Replies: 0
    Last Post: 08-13-2001, 09:07 AM