// shift right fourteen places
// uses byte pointers to long integers.
// starting value 0x7dedbeef should become 0x1f7b6;
// starting value 0x7ff02468 should become 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);
Serial.print(source, HEX);
Serial.print(" becomes ");
// this sequence takes appprox. ?? cycles
// wipe low eight bits
/*scrPad[0] = src[1];
scrPad[1] = src[2];
scrPad[2] = src[3];
*/
for (byte i = 0; i < 3; i++) {
scrPad[i] = src[i + 1];
}
// multiplying by four left shifts two bits, the upper
// bytes are used as the result
// this is faster than shifting right six bits
sPad = sPad * 4; // asm - generates a sequence of four adds to accomplish
// a single shift and the 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:
}