Float question

Discuss, ask for help, share ideas, give suggestions, read tutorials, and tell us about bugs you have found with MicroMacro in here.

Do not post RoM-Bot stuff here. There is a subforum for that.
Forum rules
This is a sub-forum for things specific to MicroMacro.

This is not the place to ask questions about the RoM bot, which uses MicroMacro. There is a difference.
Post Reply
Message
Author
ime
Posts: 8
Joined: Mon May 11, 2009 11:51 am

Float question

#1 Post by ime » Thu Jan 14, 2010 11:46 am

I'm having trouble with turning a 4byte number into its float equal. I guess I'm just missing something cause I can not find a straight answer really on google so thought I would try here.

I have a hex, 44 58 OC 92 so lets say:

Code: Select all

 number = tonumber("44580C92",16) 
Turning the hex into a the number, 1146621074, how would I get it into float form?

I see that memoryReadFloat is doing it, im guessing thats a custom function in c/c++ that you created. Will I need to do that and recompile or is there an a easier way?

User avatar
Administrator
Site Admin
Posts: 5307
Joined: Sat Jan 05, 2008 4:21 pm

Re: Float question

#2 Post by Administrator » Thu Jan 14, 2010 4:53 pm

I have no idea how you would do this, or why you would need to. Where are you getting that hex notation from?

memoryReadInt()/memoryReadFloat() makes use of C type casting, so there really isn't any special code you would need to use to convert it. Lua numbers are 'typeless' in that they can represent both integers and floats or doubles, so I doubt there really is any built-in way to do this in Lua.

ime
Posts: 8
Joined: Mon May 11, 2009 11:51 am

Re: Float question

#3 Post by ime » Thu Jan 14, 2010 10:22 pm

I have micromacro receiving packet data, which is where the hex comes from. In game that hex is a float for x,y,z coordinates.

converting that Hex into a number, I get the number "1146621074", if I view it as a float it would be 864.196411132813, which is what I want, just not sure how to do this with lua

User avatar
Administrator
Site Admin
Posts: 5307
Joined: Sat Jan 05, 2008 4:21 pm

Re: Float question

#4 Post by Administrator » Fri Jan 15, 2010 2:48 am

A quick google search has brought up a few useful articles on doing this. It's a lot of do-it-yourself, though. You'll have to understand the math, and write a bit of code to handle extracting the sign, exponent, fraction, and bias from the number.

Anyways, check these:
http://www.psc.edu/general/software/pac ... e/ieee.php
http://steve.hollasch.net/cgindex/coding/ieeefloat.html

Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests