mbf

How to convert from IEEE Python float to Microsoft Basic float

限于喜欢 提交于 2019-12-10 10:28:43
问题 I got Python float value and I need to convert it in to Microsoft Basic Float (MBF) format. Luckily, Got some code from internet that does the reverse. def fmsbin2ieee(self,bytes): """Convert an array of 4 bytes containing Microsoft Binary floating point number to IEEE floating point format (which is used by Python)""" as_int = struct.unpack("i", bytes) if not as_int: return 0.0 man = long(struct.unpack('H', bytes[2:])[0]) exp = (man & 0xff00) - 0x0200 if (exp & 0x8000 != man & 0x8000):

How to convert from IEEE Python float to Microsoft Basic float

喜夏-厌秋 提交于 2019-12-05 20:20:02
I got Python float value and I need to convert it in to Microsoft Basic Float (MBF) format. Luckily, Got some code from internet that does the reverse. def fmsbin2ieee(self,bytes): """Convert an array of 4 bytes containing Microsoft Binary floating point number to IEEE floating point format (which is used by Python)""" as_int = struct.unpack("i", bytes) if not as_int: return 0.0 man = long(struct.unpack('H', bytes[2:])[0]) exp = (man & 0xff00) - 0x0200 if (exp & 0x8000 != man & 0x8000): return 1.0 #raise ValueError('exponent overflow') man = man & 0x7f | (man << 8) & 0x8000 man |= exp >> 1

Convert MBF Single and Double to IEEE

痴心易碎 提交于 2019-12-02 08:10:52
问题 Follow-Up available: There's a follow-up with further details, see Convert MBF to IEEE. I've got some legacy data which is still in use, reading the binary files is not the problem, the number format is. All floating point numbers are saved in MBF format (Single and Double). I've found a topic about that on the MSDN boards but that one only deals with Single values. I'd also would like to stay away from API-Calls as far as I can. Does anyone have a solution for Doubles? Edit: Just in case

Convert MBF Double to IEEE

拈花ヽ惹草 提交于 2019-12-02 04:57:28
I found a topic below for convert MBF to IEEE. Convert MBF Single and Double to IEEE Anyone can explain what are the function of the code marked below? Dim sign As Byte = mbf(6) And ToByte(&H80) 'What is the reason AND (&H80)? Dim exp As Int16 = mbf(7) - 128S - 1S + 1023S 'Why is 1152 (128+1+1023)? ieee(7) = ieee(7) Or sign 'Why don't just save sign to ieee(7)? ieee(7) = ieee(7) Or ToByte(exp >> 4 And &HFF) 'What is the reason to shift 4? Public Shared Function MTID(ByVal src() As Byte, ByVal startIndex As Integer) As Double Dim mbf(7) As Byte Dim ieee(7) As Byte Array.Copy(src, startIndex,

Convert MBF Single and Double to IEEE

自作多情 提交于 2019-12-02 03:47:03
Follow-Up available: There's a follow-up with further details, see Convert MBF to IEEE . I've got some legacy data which is still in use, reading the binary files is not the problem, the number format is. All floating point numbers are saved in MBF format (Single and Double). I've found a topic about that on the MSDN boards but that one only deals with Single values. I'd also would like to stay away from API-Calls as far as I can. Does anyone have a solution for Doubles? Edit: Just in case somebody needs it, here is the VB.NET Code (it's Option Strict compliant) I ended up with (feel free to