0

How to convert 16 bit hex to float in C#? Is there any inbuilt library or I've to convert it manually?

Sample: 0xc40c5253 to -561.2863

  • 2
    @JoseLuis He wants hex-float to float, not integer. – i486 Apr 21 '16 at 09:42
  • Strongly related: [How do I turn a binary string into a float or double?](http://stackoverflow.com/q/8272733/464709) – Frédéric Hamidi Apr 21 '16 at 09:42
  • You tell us. Because Hex is integer - so any conversion is based on what binary coding the hex uses. Which you do not specify. That is like saying "give me instructions how to get from A to B" without defining A and B. – TomTom Apr 21 '16 at 09:42
  • 7
    `BitConverter.ToSingle(BitConverter.GetBytes(0xc40c5253), 0)` is `-561.2863`. Extending this code to work with hexstrings (if required) and adding caveats for the IEEE format requirement is left as an exercise to the reader(s). – Jeroen Mostert Apr 21 '16 at 09:43
  • I have the feeling I have been [here](http://stackoverflow.com/a/311179/993547) before [today](http://stackoverflow.com/a/36763464/993547). That would complete Jeroens comment. – Patrick Hofman Apr 21 '16 at 09:45
  • @i486 Oh, thank you, when I find another posts I forgot the dot. I'm sorry. :-( – Jose Luis Apr 21 '16 at 09:46

0 Answers0