Sign in to follow this  
Followers 0
Siao

Working with single precision floats in binary files

5 posts in this topic

#1 ·  Posted (edited)

Or to be more specific, the actual converting between single precision float and its hex form...

Unless I'm missing something in the documentation,

for example,

Binary(1.5) = 0x000000000000F83F, while I need 0x0000C03F

and going the opposite way ( 0x0000C03F -> 1.5 ) with current built-in AutoIt commands doesn't seem possible at all (?)

I've written functions to convert Float2Hex and Hex2Float working with strings - converting input to binary base and then converting that to output - following the steps of manual conversion;

but those are rather klutzy, esp. Float2Hex...

Is there a faster way of doing this?

Edited by Siao

"be smart, drink your wine"

Share this post


Link to post
Share on other sites



Or to be more specific, the actual converting between single precision float and its hex form...

Unless I'm missing something in the documentation,

for example,

Binary(1.5) = 0x000000000000F83F, while I need 0x0000C03F

and going the opposite way ( 0x0000C03F -> 1.5 ) with current built-in AutoIt commands doesn't seem possible at all (?)

I've written functions to convert Float2Hex and Hex2Float working with strings - converting input to binary base and then converting that to output - following the steps of manual conversion;

but those are rather klutzy, esp. Float2Hex...

Is there a faster way of doing this?

Can you please supply some code?

www.itoady.com

A* (A-star) Searching Algorithm - A.I. Artificial Intelligence bot path finding

Share this post


Link to post
Share on other sites

Or to be more specific, the actual converting between single precision float and its hex form...

Unless I'm missing something in the documentation,

for example,

Binary(1.5) = 0x000000000000F83F, while I need 0x0000C03F

and going the opposite way ( 0x0000C03F -> 1.5 ) with current built-in AutoIt commands doesn't seem possible at all (?)

I've written functions to convert Float2Hex and Hex2Float working with strings - converting input to binary base and then converting that to output - following the steps of manual conversion;

but those are rather klutzy, esp. Float2Hex...

Is there a faster way of doing this?

In the Auto3Lib A3LLibrary module, there are functions called _Lib_FloatToInt and _Lib_IntToFloat that convert a 4 byte float to/from a 4 byte int value. Simply use these and convert the output using the Hex function.

Auto3Lib: A library of over 1200 functions for AutoIt

Share this post


Link to post
Share on other sites

In the Auto3Lib A3LLibrary module, there are functions called _Lib_FloatToInt and _Lib_IntToFloat that convert a 4 byte float to/from a 4 byte int value. Simply use these and convert the output using the Hex function.

Whoa, using DllStruct...

neat and ~100 times faster :)

Thanks!


"be smart, drink your wine"

Share this post


Link to post
Share on other sites

Whoa, using DllStruct...

neat and ~100 times faster :)

Thanks!

You're welcome. :)

Auto3Lib: A library of over 1200 functions for AutoIt

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0