Shorthand operator for AND, NOT

Discussion in 'Javascript' started by Archos, Dec 19, 2011.

  1. Archos

    Archos Guest

    Does exist a shorthand assignment operator to assign AND and NOT at
    the same time? like &^=
     
    Archos, Dec 19, 2011
    #1
    1. Advertising

  2. On Dec 19, 6:33 am, Archos <> wrote:
    > Does exist a shorthand assignment operator to assign AND and NOT at
    > the same time? like &^=


    No. But with use of boolean algebra, there may be a simpler
    representation anyway for you. !(a && b) == !a || !b
     
    Michael Haufe (TNO), Dec 19, 2011
    #2
    1. Advertising

  3. Archos

    Archos Guest

    On Dec 19, 4:11 pm, "Michael Haufe (TNO)" <>
    wrote:
    > On Dec 19, 6:33 am, Archos <> wrote:
    >
    > > Does exist a shorthand assignment operator to assign AND and NOT at
    > > the same time? like &^=

    >
    > No. But with use of boolean algebra, there may be a simpler
    > representation anyway for you. !(a && b) == !a || !b


    Then ,just for archiving, the assignment "&^=" would be:
    a = a & b ^ a
     
    Archos, Dec 19, 2011
    #3
  4. On Dec 19, 5:23 pm, Archos <> wrote:
    > On Dec 19, 4:11 pm, "Michael Haufe (TNO)" <>
    > wrote:
    >
    > > On Dec 19, 6:33 am, Archos <> wrote:

    >
    > > > Does exist a shorthand assignment operator to assign AND and NOT at
    > > > the same time? like &^=

    >
    > > No. But with use of boolean algebra, there may be a simpler
    > > representation anyway for you. !(a && b) == !a || !b

    >
    > Then ,just for archiving, the assignment "&^=" would be:
    > a = a & b ^ a


    You do realize that "^" is the XOR operator and not the NOT operator
    right?

    a = a & b ^ a

    is equivalent to:
    a = a & ~b

    which is equivalent to:
    a &= ~b

    I still can't see a significant use case for "&^="
     
    Michael Haufe (TNO), Dec 21, 2011
    #4
  5. Archos

    Archos Guest

    My fault. It's for bit clear


    number &= ^(1 << x);


    On Dec 21, 7:43 pm, "Michael Haufe (TNO)" <>
    wrote:
    > On Dec 19, 5:23 pm, Archos <> wrote:
    >
    > > On Dec 19, 4:11 pm, "Michael Haufe (TNO)" <>
    > > wrote:

    >
    > > > On Dec 19, 6:33 am, Archos <> wrote:

    >
    > > > > Does exist a shorthand assignment operator to assign AND and NOT at
    > > > > the same time? like &^=

    >
    > > > No. But with use of boolean algebra, there may be a simpler
    > > > representation anyway for you. !(a && b) == !a || !b

    >
    > > Then ,just for archiving, the assignment "&^=" would be:
    > > a = a & b ^ a

    >
    > You do realize that "^" is the XOR operator and not the NOT operator
    > right?
    >
    > a = a & b ^ a
    >
    > is equivalent to:
    > a = a & ~b
    >
    > which is equivalent to:
    > a &= ~b
    >
    > I still can't see a significant use case for "&^="
     
    Archos, Dec 22, 2011
    #5
  6. Archos

    Archos Guest

    number &= ~(1 << x);

    On Dec 22, 8:44 am, Archos <> wrote:
    > My fault. It's for bit clear
    >
    > number &= ^(1 << x);
    >
    > On Dec 21, 7:43 pm, "Michael Haufe (TNO)" <>
    > wrote:
    >
    >
    >
    >
    >
    >
    >
    > > On Dec 19, 5:23 pm, Archos <> wrote:

    >
    > > > On Dec 19, 4:11 pm, "Michael Haufe (TNO)" <>
    > > > wrote:

    >
    > > > > On Dec 19, 6:33 am, Archos <> wrote:

    >
    > > > > > Does exist a shorthand assignment operator to assign AND and NOT at
    > > > > > the same time? like &^=

    >
    > > > > No. But with use of boolean algebra, there may be a simpler
    > > > > representation anyway for you. !(a && b) == !a || !b

    >
    > > > Then ,just for archiving, the assignment "&^=" would be:
    > > > a = a & b ^ a

    >
    > > You do realize that "^" is the XOR operator and not the NOT operator
    > > right?

    >
    > > a = a & b ^ a

    >
    > > is equivalent to:
    > > a = a & ~b

    >
    > > which is equivalent to:
    > > a &= ~b

    >
    > > I still can't see a significant use case for "&^="
     
    Archos, Dec 22, 2011
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. foreach shorthand

    , Mar 25, 2005, in forum: C++
    Replies:
    2
    Views:
    649
    =?iso-8859-1?Q?Ali_=C7ehreli?=
    Mar 25, 2005
  2. David W
    Replies:
    0
    Views:
    993
    David W
    Jan 17, 2007
  3. Replies:
    7
    Views:
    427
  4. asit
    Replies:
    4
    Views:
    3,728
    Roedy Green
    Jul 3, 2008
  5. Clint Olsen
    Replies:
    6
    Views:
    403
    Jeff 'japhy' Pinyan
    Nov 13, 2003
Loading...

Share This Page