// shift right fourteen places using byte pointers to longs.
// starting value 0x7deedbeef should transform to 0x1ffc0;
long source = 0x7ff02468;
//long source = 0x7dedbeef;
long destn = 0;
long sPad = 0;
//
// byte pointers to low order byte of source,
// destination and scratchpad.
// byte pointer+1 is next byte
// and so on.
byte *src = (byte*)(&source);
byte *dst = (byte*)(&destn);
byte *scrPad = (byte*)(&sPad);
void setup() {
Serial.begin(115200);
// this sequence takes appprox. ?? cycles
// wipe low eight bits
scrPad[0] = src[1];
scrPad[1] = src[2];
scrPad[2] = src[3];
// mul by four left shifts two bits
sPad = sPad * 4; // asm - generates a sequence of four adds to account for
// each byte of source and sequence is executed two times
Serial.println(sPad, HEX);
// copy remaining three upper bytes to low three bytes of destn
dst[0]=scrPad[1];
dst[1]=scrPad[2];
dst[2]=scrPad[3];
Serial.println(destn,HEX);
/* scrPad[0]=src[1];
destn=source>>14;
Serial.println(destn,HEX);
*/
}
void loop() {
// put your main code here, to run repeatedly:
}