# Shorthand operator for AND, NOT

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

1. ### ArchosGuest

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

Archos, Dec 19, 2011

2. ### Michael Haufe (TNO)Guest

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

3. ### ArchosGuest

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
4. ### Michael Haufe (TNO)Guest

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
5. ### ArchosGuest

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. ### ArchosGuest

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