Buni tushunish kerak, har bir belgi nimani anglatadi
REGISTER_NAME &= ~(1 << PINXX);
1) << - this is logical shift left. This
means that number on left side is shifted left by number of binary
position, which is in right side.
For example. 1 << 5 means 0b00000001
shifted left 5 times (while zeroes appears at right). i.e. result
will be 0b00100000 == 32.
In other words, 1 << X means "give a number, in
which only bit #X is set, and other bits are zeros"
Ok. At this point you can see that 0 << anything
gives always zero,
2) ~ - bu bitni rad etishdir. Raqamning
ikkilamchi vakolatlaridagi har bir pozitsiyada har bitning inverts
I.e. ~0b00100000 (or ~(1 << 5)) ==
Concluding, ~(1 << X) means "give a number, in which all
bits are set, except of bit #X, which is to became zero"
3) &= - this is assignment combined with
bitwise AND. I.e. X &= Y is the same that X = X &
4) & - this is bitwise AND. result of this
operation is number, in which only that bits are set, which are set
at same position in both operands, and zero otherwise.
Buning ma'nosi, agar operandlardan birida alohida bit
o'rnatilgan bo'lsa, natijada bir xil bit boshqa operandning bir xil
pozitsiyasiga teng bo'ladi. Agar bu bit yoki operandda nol bo'lsa,
natijada bir natija nol bo'ladi.
You can rephrase X &= Y in this way: "if a bit in Y
is one, leave the bit at the same position in X unchanged (whatever
it is - one or zero). If the bit in Y is zero, then clear the same
bit in X."
As was said above, ~(1 << N) gives a number where
every bit is set, except of N. So X &= ~(1 << N)
means "Clear bit #N, and remain all other bits unchanged".
Endi siz buni ko'ra olasiz
REGISTER_NAME &= (0 << PINXX);
is nonsense, because it means "Clear all the bits". It is the
same as REGISTER_NAME = 0;
By the way, if you are using assignment in this
REGISTER_NAME |= (0 << PINXX) | (1 << PINYY);
bu "set bit PINYY va aniq bit PINXX" degan ma'noni anglatmaydi,
"bit PINYY ni belgilash va bit PINXX bilan boshqa hech narsa
qilmaslik (boshqa barcha bitlardagi kabi)" degan ma'noni