bitwise operators

This is a discussion on bitwise operators within the C Programming forums, part of the General Programming Boards category; I have write a program that simulates a calculator. One of the operations the calculator has to do is the ...

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    6

    Smile 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?


  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    752
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Bitwise operators
    By gnewfenix in forum C Programming
    Replies: 2
    Last Post: 05-16-2009, 08:43 PM
  2. Bitwise Operators
    By rrc55 in forum C Programming
    Replies: 6
    Last Post: 04-30-2009, 11:37 AM
  3. Palindromes and Bitwise operators
    By Dr Tornillo in forum C Programming
    Replies: 8
    Last Post: 08-02-2007, 02:31 PM
  4. bitwise and arithmetic Operators
    By Whiteghost in forum C Programming
    Replies: 4
    Last Post: 12-28-2006, 01:13 PM
  5. Bitwise Operators, Help!!
    By Mini__C in forum C Programming
    Replies: 6
    Last Post: 07-14-2004, 04:20 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21