I want to copy certain number of bits from a variable to certain position in another variable Example: I have 8 bit of data. I want to extract higher 4 bits of this byte and transfer them to a 32 bit data variable from bit position 19. How best this can be accomplished? I tried following, but does not seem to be working. instead of 19, I should be able to copy to even from zero position.
int bitPos=19; // Position where the extracted data needs to be copied
int var1; //32 bit data
unsigned char testByte;
testByte&=0xF0; // Lower nibbles not needed
testByte=testByte>>4; // Get only higher nibble
var1|=testByte<<bitPos;