Now lets look at one line
Code:
ksfull[0] = 0 ^ (((cw[5] & 0x10) **** 4) | ((cw[6] & 0x40) **** 5) | ((cw[7] & 0x2) << 1) | ((cw[0] & 0x1) << 3) | (cw[1] & 0x10) | ((cw[7] & 0x10) << 1) | (cw[4] & 0x40) | ((cw[1] & 0x20) << 2));
This is take this template
Code:
ksfull[0] = 0 ^ ( ( eq1 ) | ( eq2 ) | ( eq3 ) | ( eq4 ) | ( eq5 ) | ( eq6 ) | ( eq7 ) | ( eq8 ) );
See there 8 eq one for each bit in a byte. What this is doing is selecting a bit of the TOTAL 65 bit CW and shifting it around to another position.
So how we select bits on C. We do bitwise-and operation
this is of the form
Code:
Byte & (bit position)
So in the previous we are saying.
Byte is
cw[5].
Bit position is 0x10.
lets see this in binary. Lets give value to cw[5]= 0x8F
0x8F = 1000 1111
0x10 = 0001 0000
And we want to do and
& And.
This means that to be 1 both bits has to have 1. If out bit selector ONLY have one bit with
1 as result we will optain the but value from it source.
0x8F = 100
0 1111
&
0x10 = 000
1 0000
-------------------
0x00 = 000
0 0000
Now imagine original is cw[5] = 0xFF
0xFF = 111
1 1111
&
0x10 = 000
1 0000
-------------------
0x01 = 000
1 0000
Ahhaaa see now the result shows the value of the bit 5 position in cw[5]. As result this is a bit select operation.
Now the original Idea is to move that bit to a new position.
(cw[5] & 0x10) > > 4) where "> >" no space means me bit X positions to the right. To move to the left we do "<<".
Again if cw[5] = 0xFF then we take our result and do "> >" 4
( 000
1 0000 ) "> >" 4 = 0000 000
1
See it is easy. We do a bitwise-and to select bit. Then we do a bitwise-move to shift bit to new position. We do 8 bitwise-or to finally add the result of all bits to construct our new byte.
Last is the symbol
| . This is a bitwise-or operation. This is used to add all 8 bit that we move to end up with a new byte. Let me show you with two bits
0001 0000 | 0010 0000 = 0011 0000
Now lets do it with 8 bits
Code:
0xAA = 1010 1010 = 0000 0000 | 0000 0010 | 0000 0000 | 0000 1000 | 0000 0000 | 0010 0000 | 0000 0000 | 1000 0000