what is the difference in <</>> and = operator

it might be awkward question to answer but i do want to know difference

As i know ‘<<’ left shift bit wise operator, one example

CLKPR = (1<<CLKPCE); // arduino pre clock setting

from the above instruction CLKPCE bit left shift 1 in CLKPR register ,So CLKPCE is 0 0 0 1

here is my question why don’t use CLKPCE = 1 instead of 1<<CLKPCE ? :roll_eyes:

naidu003:
from the above instruction CLKPCE bit left shift 1 in CLKPR register ,So CLKPCE is 0 0 0 1

Try the other way around :wink: 1 shifted CLKPR places. Think that answers the latter question :smiley:

What is the value of CLKPCE?

AWOL:
What is the value of CLKPCE?

This is what data sheet explains

CLKPR – Clock Prescale Register

Addrs
(0x64) CLKPCE - - - CLKPS3 CLKPS2 CLKPS1 CLKPS0

Bit 7 – CLKPCE:

Clock Prescaler Change Enable
The CLKPCE bit must be written to logic one to enable change of the CLKPS bits. The CLKPCE bit is only
updated when the other bits in CLKPR are simultaneously written to zero. CLKPCE is cleared by hardware four
cycles after it is written or when CLKPS bits are written. Rewriting the CLKPCE bit within this time-out period
does neither extend the time-out period, nor clear the CLKPCE bit.

So, you’ve answered your own question “why don’t use CLKPCE = 1 instead of 1<<CLKPCE ?”, because 1 != 128

Have you read my answer? (It tends to be a think that people just ignore valid answers when the don’t get them instead of asking for more explanation…)

1<<CLKPCE does not give you CLKPCE left shifted by one. And, it also doesn’t even effect CLKPCE. It gives you a new variable.

1<<CLKPCE does give you a new variable that’s a 1 shifted left CLKPCE places. So because CLKPCE is 7, it gives you 0x10000000 aka 0x80 or plain 128.

got it :slight_smile: