Saturday, May 22, 2010

List all possible ways to program the NOT function in C++.?

If you mean binary negation "~", then you can use:


~x = x ^ 0xFFFFFFFF (or however many bits your complier uses)


~x = -x - 1


or you could use a really big lookup table with every possible value in it (not very efficient)

List all possible ways to program the NOT function in C++.?
simple macro:


#define NOT(expresion) (!expresion)





or simple function:


int NOT(int expresion)


{


return !expresion;


}





example:


int b;


b = NOT(5 %26lt; 0);


/* value of b = true */


b = NOT(true);


/* value of b = false */
Reply:Well NOT is taking the Opposite. so if you created a function with 1 parameter (the variable that is being "NOT"ed) use the - (negative) sign. it work work.





NOT true = false





That's all you are doing.





Hope that helps.


No comments:

Post a Comment