|
-
Jul 15th, 2011, 06:46 PM
#1
Thread Starter
Member
RESOLVED: Conversion from 2-part 64bit Floating Point to Fixed Point
So I have already figured out how to convert 32-bit (4 byte) Floating Point numbers to Fixed Point using VB's data types from a previous forum thread, in the form shown below-
Code:
<StructLayout(LayoutKind.Explicit)> _
Public Structure DataUnion
<FieldOffset(0)> Public FloatValue As Single
<FieldOffset(0)> Public LongValue As Long
<FieldOffset(0)> Public ByteValue As Byte
End Structure
I simply send my value into the Long field and retrieve it from the Single field.
Now I have a slightly more interesting problem, though- I need to combine (not add, but concatenate) two 4 byte (Single) values into one 8 byte (Double) value, convert to Fixed Point, and round down to Single.
Here is an example of what I mean:
I am working with a piece of hardware that outputs values in 8 byte (64-bit, or Double precision) Floating Point numbers. A typical Hex value would be 40 40 DD E4 2D 3B A2 6D. Unfortunately, the hardware that I use for data capture can only receive 4 byte (32-bit, or Single precision) values, so I capture two of them at an offset (i.e. Part 1 is 40 40 DD E4 and Part 2 is 2D 3B A2 6D). There is an added level of complexity, in that the software that is doing the conversion exposes these values (in its API) as decimal values (1077992932 and 758882925 would be my inputs in this example), so I have to convert them to another form first to even combine them.
When I convert the 8-byte number by hand, I get the proper decimal fixed point value (roughly 33.733 or so) but I'm not really sure how to convert to the proper data type and combine these values in VB. Has anyone done this before?
Last edited by pgm575; Jul 20th, 2011 at 04:47 PM.
Reason: Resolved problem
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|