I don't change anything on pins but when I use first code the output is how it should be but on second output is always "16" and nothing can change it. Does anybody knows why is this happening?
Edit1: By the way i want to save things like "FFA25D" or "FF10EF" in 'rem'.
Most likely HEX has been defined as 16, and you are setting rem to that. I'm suprised the compiler isn't giving a warning, that isn't proper format for an = statement.
The HEX in your Serial.print statement is an argument for Serial.print and tells it that you want to display the variable (first argument) in hexadecimal text representation. It's not a way in C/C++ to force a hexadecimal text representation if you don't use that function (or other print functions).
This assumes that results.value is a max of 4 bytes (a 32 bit variable). The char rem[9] has place for the hexadecimal text representation of 4 bytes (hexadecimal text representation takes two characters per byte) plus the terminating NUL character. The sprintf function fills the rem array with the hexadecimal text representation of results.value.
Notes:
1)
sprintf is a little expensive on memory; that will only be an issue if you're running low on memory.
2)
It's advisable to learn not to use String (capital S) if you have limited RAM resources. If your code grows and you make heavy use of String concatenations, your code can start showing odd behaviour due to memory fragmentation.
3)
To limit what is placed in the character array, you can use snprintf; see the man page for sprintf/snprintf
alto777:
The statement, while both unusual and not what the OP had in mind, probably, is valid C or C++ syntax.
Hint: read reply 1.
a7
Anything beyond the "default" level of compiler warnings will show you the problem.
/home/pi/Downloads/arduino-1.8.8/hardware/arduino/avr/cores/arduino/Print.h:30:13: warning: left operand of comma operator has no effect [-Wunused-value]
#define HEX 16
^
/home/pi/Arduino/sketch_may03b/sketch_may03b.ino:12:25: note: in expansion of macro 'HEX'
rem = (results, HEX);
^