Thread: Bitwise operators

  1. #16
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,380
    Hmmm. It's quite frustrating. I remember from electronics at university that there are XAND-circuits. But I can't remember what they did.... I'll check it out.

  2. #17
    Unregistered
    Guest

    Bitwise operators

    I understand that there is no defined XAND but what im trying to do is some thing like this

    00000011 AND
    00000101
    -----------
    00000001 ~
    -----------
    11111110

    = XAND

    here is the XAND Truth table
    input a | input b| output
    0 0 1
    1 0 0
    0 1 0
    1 1 1

    Is getting a truth table like that in C?

    thanks

  3. #18
    Blank
    Join Date
    Aug 2001
    Posts
    1,034
    That's the NXOR function I think.

  4. #19
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    I understand that there is no defined XAND but what im trying to do is some thing like this

    00000011 AND
    00000101
    -----------
    00000001 ~
    -----------
    11111110
    So where's the hard part? Just combine an & and a ~.

    x ~= (a & b);

    ...or...

    #define XAND(a,b) ~(a&b)

    x = XAND(a,b);

    Quzah.
    Hope is the first step on the road to disappointment.

  5. #20
    Unregistered
    Guest

    Smile Bitwise operators

    I was just makeing sure that it could be done and that my thought process on how to do it was right.

    THanks

  6. #21
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,380
    This is how a XAND works: If only one of the input bits is 0, then the output is high.

    It's the opponent of the XOR: If only one of the input bits is 1, then the output is high.

    Note that for 2 input bits, the XAND behaves like a XOR. But when having more than 2 input bits, you can see the differences.

    This little program will illustrate this:

    Code:
    #include <stdio.h>
    
    int main (void)
    {
        unsigned char a, b, c;
        unsigned char s;
        
        a = 0xFF;
        b = 0xB5;
        c = 0x9D;
            
        s = ~a ^ ~b ^ ~c;
    
        printf ("XAND (%02X, %02X, %02X) = %02X\n", a, b, c, s);
        
        return 0;    
    }

  7. #22
    Insomniac
    Join Date
    Mar 2004
    Posts
    35
    Very helpful thread! Thanks for the added information.

    Great explanation from Deckard!
    </reincarnation>

  8. #23
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Gee, over 2 years old and then you bump the thread!
    Nice going
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

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, 02:13 PM
  5. Bitwise Operators, Help!!
    By Mini__C in forum C Programming
    Replies: 6
    Last Post: 07-14-2004, 04:20 PM