Home > other >  How to put a hex positive (two bytes) converted to a decimal
How to put a hex positive (two bytes) converted to a decimal

Time:09-18

18 b20 temperature temp, I use a number of two bytes
I want to let him become a decimal number, how to do?

CodePudding user response:

Float fTemp=((H<8) | L) * 0.0625;



CodePudding user response:

Float fTemp=((((short) H<8) | L) * 0.0625);

CodePudding user response:

refer to the second floor zgl7903 response:
float fTemp=((((short) H<8) | L) * 0.0625);

What do you mean, look not to understand, for example, I got the temp (two bytes)
How to turn? Actually I want to realize the alarm when temperature is greater than a certain value, such as greater than 25,
Compared to want to let the temp and 25, but not always
Easy to understand, ok, I can't understand, what is that L? H is what

CodePudding user response:

H high byte L low byte
On the technical manual yes

CodePudding user response:

Decimal number also use hexadecimal save memory, lz should is to ask how can be converted to decimal display? Then use the printf (" % d ", m)

CodePudding user response:

Show you two functions, can help you:

/* '* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * "*/
/* "Function: lib_CharToBcd" */
/* "Description: single-byte hexadecimal number turn BCD" */
/* "Input: srcData: single-byte hexadecimal number" */
/* "Output: no" */
/* "Return: conversion results (single-byte BCD)" */
/* '* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * "*/
Uint8 lib_CharToBcd (uint8 srcData)
{
Uint8 data, high4;

Data=https://bbs.csdn.net/topics/(uint8) (srcData % 100);
High4=(uint8) (data/10);
Return ((uint8) ((high4 & lt; <4) | (uint8) (10) data %));
}

/* '* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * "*/
/* "Function: lib_ShortToBcd" */
/* "Description: 2 bytes hexadecimal number turned 2 bytes BCD" */
/* "Input: srcData: 2 bytes hexadecimal number" */
/* "Output: destData: after the conversion of BCD pointer" */
/* "Return: there is no" */
/* '* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * "*/
Void lib_ShortToBcd (uint8 * srcData, uint8 * destData)
{
Uint8 I;
Uint8 temp.
Uint16 scrTmp;

Memcpy (srcData, (uint8 *) & amp; ScrTmp, 2);
for(i=0; i<2; I++)
{
Temp=(uint8) (scrTmp % 100);
* (destData + I)=lib_CharToBcd (temp);
ScrTmp/=100;
}
}

CodePudding user response:

Get the value of the direct comparison can, as long as it is byte type can be compared

CodePudding user response:

5, the conversion character
% % percentage printed symbols, not conversion,
% c character to the output buffer, not conversion,
% d integer converted to decimal,
% f times precision digital into floating point Numbers,
% o integer into eight carry,
% s string output to the buffer, not conversion,
% x an integer converted to lowercase hexadecimal,
% X an integer to uppercase hexadecimal,
For example:
1
2
3
4
5
Money=123.1
Formatted=sprintf (" % 06.2 f ", $money);//the variable $formatted value for the "123.10"
Formatted=sprintf (" % 08.2 f ", $money);//the variable $formatted value for the "00123.10"
Formatted=sprintf (" % 08.2 f ", $money);//the variable $formatted value for the "123.1000"
Formatted=sprintf (" % 2 f % % ", 0.95 * 100);//formatted as percentage

CodePudding user response:

It is a decimal

CodePudding user response:

reference qq_45778701 reply: 3/f
Quote: refer to the second floor zgl7903 response:
float fTemp=((((short) H<8) | L) * 0.0625);

What do you mean, look not to understand, for example, I got the temp (two bytes)
How to turn? Actually I want to realize the alarm when temperature is greater than a certain value, such as greater than 25,
Compared to want to let the temp and 25, but not always
Easy to understand, ok, I can't understand, what is that L? H is what


H high byte
L low byte
  • Related