logical operator !

This is a discussion on logical operator ! within the C Programming forums, part of the General Programming Boards category; Is there a way to do a ! operation using only ~ & ^ | + << or >> For ...

  1. #1
    Registered User
    Join Date
    Feb 2005
    Posts
    7

    logical operator !

    Is there a way to do a ! operation using only ~ & ^ | + << or >>


    For example, instead of doing !! (a ^ x) (where a is = 0)

    I've done something to the effect of:

    Code:
    int x;
    x = (1 << x);
    x = (x + 1) & 1;
    return x;
    }
    It works for everything except 0x80000000 on a 32bit os.

    thanks,

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    Why do you want to do this? It sounds suspiciously like a homework restriction.
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Smart pointer class
    By Elysia in forum C++ Programming
    Replies: 63
    Last Post: 11-03-2007, 07:05 AM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  3. logical operator OR not working?
    By echo49 in forum C Programming
    Replies: 4
    Last Post: 09-12-2006, 04:26 AM
  4. Logical Operator not working?
    By xshapirox in forum C++ Programming
    Replies: 2
    Last Post: 09-27-2004, 05:21 AM
  5. operator overloading and dynamic memory program
    By jlmac2001 in forum C++ Programming
    Replies: 3
    Last Post: 04-06-2003, 11:51 PM

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