Home > Back-end >  I ask, how to put the hexadecimal 2 byte value 10 x magnification in the message
I ask, how to put the hexadecimal 2 byte value 10 x magnification in the message

Time:12-03

In dealing with a thermostat, I need to read a message of value, and then sent to the APP,
Temperature data part of the message is ten times to enlarge the decimal values, in a converted to hexadecimal send,
Such as: the current temperature 30, address + command code + 485 + [data] + check=00 01 00 01 [c] 2 01 xx xx,
Excuse me, what is the easy way to hexadecimal Numbers into decimal, 10 x magnification and then converted to hexadecimal?

CodePudding user response:

Strtol
itoa

CodePudding user response:

 unsigned char data [2]; 
Short int temperature;
Short int temperature10;
Temperature=30;
Temperature10=10 * temperature;
Data [0]=(unsigned char) (temperature10/256);
Data [1]=(unsigned char) (temperature10%256);
  • Related