Extracts the low (rightmost) 8 bits from a larger data type. Useful when you are dealing with communication protocols (like I2C, SPI, serial) where data must be sent in bytes, or when manually splitting numbers.
Use the following function to extract the first 8 bits from a variable:
lowByte(x)
The function admits the following parameter:
x: input variable to extract from. Data type: any type.
The function returns the byte extracted from the original variable. Data type: byte.
unsigned int x = 0xABCD; // Hexadecimal 43981
void setup() {
Serial.begin(9600);
byte low = lowByte(x); // Extracts 0xAB (171 decimal)
Serial.print("The low byte is: ");
Serial.println(low, HEX); // Prints "CD"
}
void loop() {
}
This is what the lowByte() function does behind the scenes:
#define lowByte(w) ((uint8_t) ((w) & 0xFF))