byteRead macro

Dear all,

Please find below the definition of a byteRead macro, something similar to the bitRead function, but for bytes.

Hope this helps,

// ------------------------------------------------------------------------------------------
// byteRead macro definition. Francois Auger, Universite de Nantes, France, November 19, 2016
#define byteRead(x,n) ( ( ( (unsigned char) (&x) + n) ) )
// ------------------------------------------------------------------------------------------

void setup() {
Serial.begin(9600); // serial port initialization
while (!Serial) { // wait for serial port to connect. Needed for Leonardo only
}
Serial.println(F("byteReadDemo program started"));
}

void loop() {
int N1 = 1025;
Serial.print(N1); Serial.print(" = "); Serial.print(byteRead(N1,1)); Serial.print("*256 + "); Serial.println(byteRead(N1,0));

word N2 = 1025;
Serial.print(N2); Serial.print(" = "); Serial.print(byteRead(N2,1)); Serial.print("*256 + "); Serial.println(byteRead(N2,0));

long int N3 = 70000;
Serial.print(N3); Serial.print(" = ");
Serial.print(byteRead(N3,3)); Serial.print("*16777216 + "); Serial.print(byteRead(N3,2)); Serial.print("*65536 + ");
Serial.print(byteRead(N3,1)); Serial.print("*256 + "); Serial.println(byteRead(N3,0));

float x=M_PI;
Serial.print(byteRead(x,3)); Serial.print("/"); Serial.print(byteRead(x,2)); Serial.print("/");
Serial.print(byteRead(x,1)); Serial.print("/"); Serial.println(byteRead(x,0));

delay(1000);
}

thanks for posting.

So what do I get with byteRead(7*5ul, 2) or byteRead(M_PI*2, 2)?

(that's the pb with macros, you should modify this for an inline function)

I think more problematic is:
int i;
byteRead(i,3);

KeithRB:
I think more problematic is:
int i;
byteRead(i,3);

as well