Description

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.

Syntax

Use the following function to extract the first 8 bits from a variable:

lowByte(x)

Parameters

The function admits the following parameter:

x: input variable to extract from. Data type: any type.

Returns

The function returns the byte extracted from the original variable. Data type: byte.

Example Code

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() {
}

Note

This is what the lowByte() function does behind the scenes:

#define lowByte(w) ((uint8_t) ((w) & 0xFF))

See also