How to Use Word() Function in Arduino?

ArduinoHardwareSoftware & Coding

The word() function converts a variable of any data type to the word data type. It is essentially a cast function.


The syntax is −


Where var is a variable of any datatype.

Alternatively, you can also construct a word by specifying two bytes, the higher byte and the lower byte.


The syntax is −

word(highByte, lowByte)

For instance, word(2,5) will return 517 (2 is 0b00000010 and 5 is 0b00000101; word(2,5) will return 0b0000001000000101, which equals 517).

You can try out other combinations of characters and data types. You can read more about the word function from Arduino’s official documentation here.

Updated on 30-Jul-2021 15:08:15