3

I have a decimal number (such as 0.15625) which is stored as 32-bit floating point (fp32) number (0-01111100-01000000000000000000000 (sign-exponent-mantissa)) in memory. I want to convert that fp32 to fp16, and then show it in decimal. I guess the original and converted decimal numbers should be approximately same.

Obviously to store the converted number in memory I need to show that fp16 version (which is 16 bits) in 32 bits.

I am looking for a bunch of code in Matlab or C++ to do this conversion.

Your support is really appreciated.

ard24ie
  • 181
  • 3
  • 12
  • possible duplicate of [32-bit to 16-bit Floating Point Conversion](http://stackoverflow.com/questions/1659440/32-bit-to-16-bit-floating-point-conversion) – NathanOliver May 28 '15 at 17:46
  • Matlab does not natively support half-precision. See also: [is float16 supported in matlab?](http://stackoverflow.com/questions/12170950/is-float16-supported-in-matlab). You could also try [this FileExchange submission](http://www.mathworks.com/matlabcentral/fileexchange/23173-ieee-754r-half-precision-floating-point-converter) – horchler May 28 '15 at 20:26
  • So, what have you tried alerady? Are you going to write code in c++ or in Matlab. As already stated, matlab does not natively support 16-bit float (or `half` as it is called). This also mean that both Matlab code and mex might fail. There are extensions to c and c++ which implement `half, eg http://half.sourceforge.net/ and http://cellperformance-snippets.googlecode.com/files/half.c – patrik May 29 '15 at 06:10

0 Answers0