Shifting bits from one variable to another

Hi all,

I have two variables, for example:

var1=B00000000;
var2=B11111111;

When I align them like this:
0000000011111111

I want that all bits shift to left (i.e. by 2 positions), so that result would be;
0000001111111100

And final result that I need is:
var1=B00000011;
var2=B11111100;

How to make this manipulation, if possible without copying bit-by-bit from one var to another?

  uint16_t combined;
  combined = (uint16_t) var1 << 8;
  combined |= var2;
  combined <<= 2;

DrugMile:
How to make this manipulation, if possible without copying bit-by-bit from one var to another?

another way would be a union:

union MyUnion {
  uint8_t bytes[2];
  uint16_t value;
};


void setup() 
{
  Serial.begin(9600);
  MyUnion newVal;
  newVal.bytes[0] = 0b11111111;
  newVal.bytes[1] = 0b00000000;
  Serial.println(newVal.value, BIN);
  newVal.value <<= 2;
  Serial.println(newVal.value, BIN);
  Serial.println(newVal.bytes[0], BIN);
  Serial.println(newVal.bytes[1], BIN);
}

void loop() {
  // put your main code here, to run repeatedly:

}

BulldogLowell:
another way would be a union:

May not be portable. Depends on Endianness.

gfvalvo:
May not be portable. Depends on Endianness.

are we not working with Arduino here?

BulldogLowell:
are we not working with Arduino here?

"Arduino" the board? "Arduino" the IDE? To me, lots of different processors are part of the "Arduino" ecosystem.

Thanks, I see some new stuff for me here, I'll have to study more into it.

gfvalvo:
To me, lots of different processors are part of the "Arduino" ecosystem.

and which are big endian?