# what is this instruction will do in code |=(1<<x)

hi, I have got a an example code for reading ADC values from arduino uno board on ADC5 pin

I would like to know that what “logical or equals” do in this ADCSRA |=(1<<ADSC);

what is the difference in =(1<<x) and |=(1<<x) ?

``````int A=0;

void setup()
{
Serial.begin(19200);
}

void loop() {

Serial.println(A);
}

{
ADMUX   =  (1<<REFS0)| (1<<MUX0) | (1<<MUX2);                             // Avcc(5v) ref voltage and ADC5 selection

Start_Conversion();
}

void Start_Conversion()
{
}

{
Start_Conversion();
}
``````

have you read the guide on bitwise operators?

C has a number of operators like this: +=, |=, &=, -=, /=, *= . They all do the same thing - a combination of a binary operator and an assigment.

a *= b; multiplies a by b and assigns the result to a
a += b; adds a and b and assigns the result to a
a |= b; does a bitwise or of a and b and assigns the result to a

so

`````` DIDR0 |= (1<<ADC5D);
``````

is the same as

`````` DIDR0  = DIDR0 | (1<<ADC5D);
``````

Historically, C has close ties to assembler-language programming. On many machines, |= becomes a single machine-language instruction. These days, compilers are smart enough to figure that out even if you don’t use the combined operator, but it’s part of the C language and is an instantly-recognisable idiom for C programmers. This line of code sets the ADC5D bit in DIDR0.

And, if what you are modifying is a complicated expression it can prevent errors.

Why type *(a->b.c[I*j+k - *g]) twice?