What are XAND and XOR

后端 未结 17 1460
旧巷少年郎
旧巷少年郎 2020-12-06 04:51

What are XAND and XOR? Also is there an XNot

17条回答
  •  甜味超标
    2020-12-06 05:49

    In most cases you won't find an Xand, Xor, nor, nand Logical operator in programming, but fear not in most cases you can simulate it with the other operators.

    Since you didn't state any particular language. I won't do any specific language either. For my examples we'll use the following variables.

    A = 3
    B = 5
    C = 7

    and for code I'll put it in the code tag to make it easier to see what I did, I'll also follow the logic through the process to show what the end result will be.

    NAND

    Also known as Not And, can easily be simulated by using a Not operator, (normally indicated as ! )

    You can do the following

    if(!((A>B) && (B

    if (!(F&&T))
    if(!(F))
    If(T)

    In our example above it will be true, since both sides were not true. Thus giving us the desired result

    NOR

    Also known as Not OR, just like NAND we can simulate it with the not operator.
    if(!((A>B) || (B

    if (!(F||T))
    if(!(T))
    if(F)

    Again this will give us the desired outcomes

    XOR

    Xor or Exlcusive OR only will be true when one is TRUE but the Other is FALSE

    If (!(A > C && B > A) && (A > C || B > A) )

    If (!(F && T) && (F || T) )
    If (!(F) && (T) )
    If (T && T )
    If (T)

    So that is an example of it working for just 1 or the other being true, I'll show if both are true it will be false.

    If ( !(A < C && B > A) && (A < C || B > A) )

    If ( !(T && T) && (T ||T) )
    If ( !(T) && (T) )
    If ( F && T )
    If (F)

    And both false

    If (!(A > C && B < A) && (A > C || B < A) )

    If (!(F && F) && (F || F) )
    If (!(F) && (F) )
    If (T && F )
    If (F)


    And the picture to help

    XAND

    And finally our Exclusive And, this will only return true if both are sides are false, or if both are true. Of course You could just call this a Not XOR (NXOR)

    Both True If ( (A < C && B > A) || !(A < C || B > A) )

    If ((T&&T) || !(T||T))
    IF (T || !T)
    If (T || F)
    IF (T)

    Both False If ( (A > C && B < A) || !(A > C || B < A) )

    If ( (F && F) || !(F ||F))
    If ( F || !F)
    If ( F || T)
    If (T)

    And lastly 1 true and the other one false. If ((A > C && B > A) || !(A > C || B > A) )

    If ((F && T) || ! (F || T) )
    If (F||!(T))
    If (F||F)
    If (F)

    Or if you want to go the NXOR route...
    If (!(!(A > C && B > A) && (A > C || B > A)))

    If (!(!(F && T) && (F || T)) )
    If (!(!(F) && (T)) )
    If (!(T && T) )
    If (!(T))
    If (F)

    Of course everyone else's solutions probably state this as well, I am putting my own answer in here because the top answer didn't seem to understand that not all languages support XOR or XAND for example C uses ^ for XOR and XAND isn't even supported.

    So I provided some examples of how to simulate it with the basic operators in the event your language doesn't support XOR or XAND as their own operators like Php if ($a XOR $B).

    As for Xnot what is that? Exclusive not? so not not? I don't know how that would look in a logic gate, I think it doesn't exist. Since Not just inverts the output from a 1 to a 0 and 0 to a 1.

    Anyway hope that helps.

提交回复
热议问题