Hi again
So I haven’t had much programming time, but recently finished that step handling five bits.
I went for... if the bit either side of the centre bit was set, the new middle bit will be set in the output byte.
The next question I would like to ask is, say I have an array of “bitbyte[s]”, how do I bitwise rotate the LS bit
of each byte in the array? like a two dimensional array that would be easy if it was done with bigger variable types.
The best I can think of is iterate the array, checking with & ,then writing the next bit with | in sequence,
essentially doing a similar thing as the first step?
Code:
unsigned char bitbyte = 0b11111011;
unsigned char opabyte = 0;
unsigned char opbbyte = 0;
unsigned char outbyte = 0;
unsignedchar midbyte = 0; // buffer to store middle bit
if (cntone == 0) {
bitbyte = bitbyte & 0x1F; // clear most significant three bits
opabyte = bitbyte & 0x03; // seperate nibble pairs
opbbyte = bitbyte & 0x18; // leaving middle bit alone
midbyte = bitbyte & 0x0A; // store bits surrounding middle bit
NSLog(@":%02x ",opabyte); // working nibble values
NSLog(@":%02x ",opbbyte); //
opabyte = opabyte << 1; // shift nibbles left and right
opbbyte = opbbyte >> 1; //
outbyte = opabyte | opbbyte; // superimpose nibbles to new byte
if (midbyte != 0) { // correct the middle bit
outbyte = outbyte | 0x04; // set middle bit
} else { // cycle time balance
bitbyte = bitbyte | 0x04; // don't need the input value anymore
} // midbyte
NSLog(@":%02x ",opabyte); // working nibble values
NSLog(@":%02x ",opbbyte); //
NSLog(@":%02x ",outbyte); // result byte value
NSLog(@" "); // spacer
if (cntone < 1) { // not needed for cyclic implementation
cntone++; // calculate and send to log only once
}
}
next step I’m asking about:
Code:
x x x x x x
x x xx x x
x xx x x x
x x x x x x x
xx x xx x x x
x x x x x
x x x