Output of highByte() function [Solved]

This question is in line with producing 32 bit variables after mixing floats with integers in an equation.

' any byte = highByte( any integer ) ; ' works as promised.

BUT is the output really eight bits, or is it sixteen bits (influenced by the use of an integer) with the top eight bits padded with zeros?

In any case, I will not use ' any byte = bitRead( output from highByte() function ), value greater than 7); ' for fear of inputting corrupted data.

thanks Hugh

highByte is a macro as follows:

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

As such, it will "return" an 8 bit value due to the (uint8_t) cast.

But if you assigned that to something else then the value carried forward will be defined by the data type you assigned the result to. For example, the value carried forward in the following will be a 32 bit long value:

  unsigned long in = 0x123456;
  unsigned long out = highByte(in);

Thus out will carry 0x34 forward within a 32 bit variable.

You can test this for yourself. Note that highByte takes the high byte of a 16 bit value (i.e. 0x3456 in my example), not the high byte of the value provided (i.e. 0x00 in my example).

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

"or the second lowest byte " ... doesn't perplexing.

Thank you gm310509 and gcjr.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.