RTduino Source Code Reference Manual
Macros | Typedefs
and Bytes

Bit and byte data type definitions. More...

Macros

#define LSBFIRST   0
 Least Significant Bit first.
 
#define MSBFIRST   1
 Most Significant Bit first.
 
#define bit(b)   (1UL << (b))
 Computes the value of the specified bit (bit 0 is 1, bit 1 is 2, bit 2 is 4, etc.). More...
 
#define bitRead(value, bit)   (((value) >> (bit)) & 0x01)
 Reads the value of a specific bit. More...
 
#define bitSet(value, bit)   ((value) |= (1UL << (bit)))
 Sets a specific bit. More...
 
#define bitClear(value, bit)   ((value) &= ~(1UL << (bit)))
 Clears a specific bit. More...
 
#define bitToggle(value, bit)   ((value) ^= (1UL << (bit)))
 Toggles a specific bit. More...
 
#define bitWrite(value, bit, bitvalue)   ((bitvalue) ? bitSet(value, bit) : bitClear(value, bit))
 Writes a specific bit. More...
 
#define lowByte(w)   ((uint8_t) ((w) & 0xff))
 Extracts the low-order (rightmost) byte of a variable (e.g. a word). More...
 
#define highByte(w)   ((uint8_t) ((w) >> 8))
 Extracts the high-order (leftmost) byte of a word (or the second lowest byte of a larger data type). More...
 

Typedefs

typedef unsigned int word
 Represents a 16-bit unsigned integer.
 
typedef bool boolean
 Represents a boolean value (true or false).
 
typedef uint8_t byte
 Represents an 8-bit unsigned integer.
 

Detailed Description

Bit and byte data type definitions.

Macro Definition Documentation

◆ bit

#define bit (   b)    (1UL << (b))

Computes the value of the specified bit (bit 0 is 1, bit 1 is 2, bit 2 is 4, etc.).

Warning
Please define F_CPU in pins_arduino.h
Parameters
bThe bit whose value to compute. Note that n needs to be between 0-31 (32 bit).
Returns
The value of the specified bit.
See also
https://www.arduino.cc/reference/en/language/functions/bits-and-bytes/bit

◆ bitClear

#define bitClear (   value,
  bit 
)    ((value) &= ~(1UL << (bit)))

Clears a specific bit.

Parameters
valueThe number in which to clear a bit.
bitWhich bit to clear, starting at 0 for the least-significant (rightmost) bit.
Returns
The value of the numeric variable after the bit at position n is cleared.
See also
https://www.arduino.cc/reference/en/language/functions/bits-and-bytes/bitclear

◆ bitRead

#define bitRead (   value,
  bit 
)    (((value) >> (bit)) & 0x01)

Reads the value of a specific bit.

Parameters
valueThe number from which to read.
bitWhich bit to read, starting at 0 for the least-significant (rightmost) bit.
Returns
The value of the specified bit (0 or 1).

Reads a bit of a variable, e.g. bool, int. Note that float & double are not supported. You can read the bit of variables up to an unsigned long long (64 bits / 8 bytes).

See also
https://www.arduino.cc/reference/en/language/functions/bits-and-bytes/bitread

◆ bitSet

#define bitSet (   value,
  bit 
)    ((value) |= (1UL << (bit)))

Sets a specific bit.

Parameters
valueThe number in which to set a bit.
bitWhich bit to set, starting at 0 for the least-significant (rightmost) bit.
Returns
The value of the numeric variable after the bit at position n is set.

Sets a bit of a variable, e.g. bool, int. Note that float & double are not supported. You can set the bit of variables up to an unsigned long long (64 bits / 8 bytes).

See also
https://www.arduino.cc/reference/en/language/functions/bits-and-bytes/bitset

◆ bitToggle

#define bitToggle (   value,
  bit 
)    ((value) ^= (1UL << (bit)))

Toggles a specific bit.

Parameters
valueThe number in which to toggle a bit.
bitWhich bit to toggle, starting at 0 for the least-significant (rightmost) bit.
Returns
The value of the numeric variable after the bit at position n is toggled.
See also
https://www.arduino.cc/reference/en/language/functions/bits-and-bytes/bittoggle

◆ bitWrite

#define bitWrite (   value,
  bit,
  bitvalue 
)    ((bitvalue) ? bitSet(value, bit) : bitClear(value, bit))

Writes a specific bit.

Parameters
valueThe number in which to write a bit.
bitWhich bit to write, starting at 0 for the least-significant (rightmost) bit.
bitvalueThe value to write (0 or 1).
Returns
The value of the numeric variable after the specified bit is written.
See also
https://www.arduino.cc/reference/en/language/functions/bits-and-bytes/bitwrite

◆ highByte

#define highByte (   w)    ((uint8_t) ((w) >> 8))

Extracts the high-order (leftmost) byte of a word (or the second lowest byte of a larger data type).

Parameters
wA value of any type.
Returns
The high-order (leftmost) byte of the value.
See also
https://www.arduino.cc/reference/en/language/functions/bits-and-bytes/highbyte

◆ lowByte

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

Extracts the low-order (rightmost) byte of a variable (e.g. a word).

Parameters
wA value of any type.
Returns
The low-order (rightmost) byte of the value.
See also
https://www.arduino.cc/reference/en/language/functions/bits-and-bytes/lowbyte