Translate this to me please :)

Hello everybody,

could you please help me understand what this line means?

#define DEFINITION (1<<0)

I know what "#define" does: It's the use of the shift operator in brakets (1<<0) part that I do not understand.

Thanks in advance!

This line is the same as

#define DEFINITION  1

The shift operator is used, probably to emphasize that it is setting zero-position bit to state 1.

Addition:
See the similar example:

(1 << 5)

Set bit 5 to the state 1

Agree with @b707 (although I'd say bit 5 rather than 5th bit given they are numbered 7-0)... a bit (see what I did there?) redundant in this case but for a different bit then makes sense

agree... corrected.

clear: thank you very much!

Also seen

 (1 << WGM12)

when you get to names bits in the low level stuff going on.

Above makes a number with one one, a single bit set, which bit is in the position WGM12 is at in some control register.

These days ppl use

bit(5)

or

bit(WGM12)

Which does the same thing.

Personally old school here, I like the shift method. I never saw it outside of Arduino. I think maybe it is part of the Arduino gift that never stops giving.

a7

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.