Number Conversion Functions (2 x Int to float, 32 bit binary to float, etc.)
Version Compatibility: Visual Basic 6, Visual Basic 5
Here are some simple number conversion routines that can be used for many applications, typically comms - e.g. a float from a Modbus device is provided as two integers - one of these routines will take the two integers and convert them to an IEEE float. Included functions are: Two ints to a float, Float to array of 2 ints, 32 bit binary string to float, Float to 32 bit binary string, Base converter function - i.e. any integer to binary, Binary String to Byte converter. I have found many posts on various sites asking how to convert numbers, many of which refer to how the IEEE standards store numbers in memory (sign, exponent, mantissa) and how binary normalization is used. All this is quite overkill for someone who just wants to convert a number! It's simple how it works. The CopyMem API function is used to copy the memory behind an input parameter (e.g. float) to the memory of two integers.
Instructions: Copy the declarations and code below and paste directly into your VB project.