0

I am use the CCS compiler to microcontroller and I am taking a frame of reads from a RTU in hexadecimal of 2 bytes (16 bist) which I store in an int16 array, these stored data are floating point numbers in IEEE 754 half-precision representation, I need to perform arithmetic operations with these reads and the only one way to do them is to convert these numbers to float:

Example:

Number   float           IEEE 754 

A        12.50          0x4A40
B        11.75          0x49E0

A+B      24.25          0x4E10

if I did the operation as simple hexadecimal sums A + B = 0x4A40 + 0x49E0 = 0x9420 which is totally different from the value obtained if I work with its float representation 0x4E10, I need the conversion algorithms to port it to the compiler that I use

DarioG
  • 83
  • 7
  • How are you storing a "base ten decimal number"? Such a thing is not standard in C++. So, effectively, you're asking for an algorithm to convert something that is unspecified to half-precision IEEE-754. – Peter Oct 04 '20 at 02:35
  • @Peter I'd assume that's just a really awkward way of saying `int`. – Mark Ransom Oct 04 '20 at 02:42
  • @MarkRansom - Maybe. I've also seen the occasional question here about how to convert a base 10 decimal number to an `int`, or vice versa, so I wouldn't assume anything. – Peter Oct 04 '20 at 03:17
  • Does this help? https://stackoverflow.com/questions/12817410/convert-int-to-16bit-float-half-precision-floating-point-in-c – parktomatomi Oct 04 '20 at 03:23
  • @Peter the question was edited, you were right to be skeptical. – Mark Ransom Oct 04 '20 at 15:38

0 Answers0