-
bitwise operators
I have write a program that simulates a calculator. One of the operations the calculator has to do is the inclusive OR | (bitwise operator). It should also work for positive and negative numbers.
Would this work??
case '|':
op1 = pop(); //op1 and op2 are of type double
op2 = pop();
if( op1 == '-' && isdigit(op2) )
push( (int)op1 | (int)op2);
I also have to convert the these valves (op1 and op2) to int type is the that the correct way?
:)
-
Everything in the code looks to make sense except for this bit...
Code:
if( op1 == '-' && isdigit(op2) )
If op1 and op2 are of type double, why perform char type comparisons on them? I don't see why your routine shouldn't work as long as you get rid of that line.