Wire.write

Hi, why does "Wire.write(0x80);" result in an error message? "Wire.write((byte)0x80);" and "Wire.write(128);" are accepted! Why do I need to specify the type of hexadecimal values (that are in the range of the expected type), but not of decimal values?

Why do I need to specify the type of hexadecimal values (that are in the range of the expected type), but not of decimal values?

In the absence of directions to the contrary, literals are interpreted as ints. The Wire.write() method has an overload that takes an int, so the compiler knows which overload to use.

The hex values are not interpreted as ints. They are just numeric values, so the compiler could treat them as ints, as pointers, or in a variety of other ways. Since more than one version of the Wire.write() function could possibly be called with 0x80 as valid input, the compiler can't choose the best method, so you must make the decision.

…I’m from the “C”-world and forgot that the IDE is written in “C++” with the possibility of overloaded methods, but why is there a difference between hex and dec values?

but why is there a difference between hex and dec values?

I didn't write the compiler. I didn't make the difference. I simply know that it exists, and why.