Sign in to follow this  
nickpike

Conversion Reversal

Recommended Posts

Does anybody know how to reverse the following formula. Basically, I want to undo this conversion. It's in this C++ speak that I don't understand. If anyone can do this, I'll probably then ask for the XML equivalent reversal. If I get this to work, I'll then share the info. NOTE, I have added a space after the 8 to stop a smiley from showing Conversion: Y = 100 * (1000000 + ((x >> 20) & 0xF)*100000) + ((x >> 16) & 0xF)*10000) + ((x >> 12) & 0xF)*1000) + ((x >> 8 ) & 0xF)*100) + ((x >> 4) & 0xF)*10) + ((x) & 0xF))) cheers, nick

Share this post


Link to post
Share on other sites
Help AVSIM continue to serve you!
Please donate today!

Hi,You can't reverse it as there is an AND operator - the result would be ambiguous.e.g.:11reversed could be:00 && 11-- or --10 && 01That's the problem. :( You could start branching into probability of which would be the most likely answer, but I think that is way beyond the scope of FS.Best regards,Vulcan.

Share this post


Link to post
Share on other sites

I replied to this in another forum:It isn't syntatically correct - the numbers of opening and closing brackets aren't equal.Ignoring that and assuming x is unsigned long or a DWORD, it appears to extract packed BCD(?) digits from the lower nibbles (4 bits) of x and build a positive integer in the range 100 - 200 million and assign it to Y. Although it is possible reverse the expression to calculate the packed BCD value of (Y/100) - 1000000 and put it in the lower 20 bits of x, it isn't possible to determine what the remaining upper bits of x should be set to from the information available.The ANDing has nothing do with ambiguity, given that 0xF sets all 4 bits (1111). ((x >> 20) & 0xF), for example, shifts right by 20 bits then extracts the lower 4 bits unambiguously.Anyway, the ANDing is bitwise (&) not logical (&&) and the examples you give both AND to 00 not 11.00 & 11 = 0010 & 01 = 00

Share this post


Link to post
Share on other sites

it seems to be BCD convertion. Given the numeric ranges, it looks like frequency packed in BCD converted to its numeral form.For example: say frequency is 136.50 I would assume from your code it would be BCD packed in the following way (shown in hexadecimal)0x00365000This is a typical 16.16 fix point format (the 2 MSB are integer frequency and the 2 LSB are fractional frequency)The code then extract each individual BCD digit (1 then 3 then 6 etc...)Y = 100 * (10000000 + (3 * 100000) + (6 * 10000) + (5 * 1000) + (0 * 100) + (0 * 10) + 0)this would give: 100 * 1365000 = 136500000It is often used the way around:(1.0 / 1000.0) * 1365000 = 136.5Hope this helps!

Share this post


Link to post
Share on other sites

Many thanks. Your logic is spot-on. It takes a frequency and then applies the conversion (but shouldn't have done). I think it converts the frequecy to a BCD number.If I understand this properly, the proper frequency digits are recognisable in the result.I know that, say, a frequency of 113.90 becomes 230604000.Can you shed any more light on this. If your thinking is correct, how would you convert the number back to a frequency?Cheers and thanks for the help,nick

Share this post


Link to post
Share on other sites

Hi,Would be interesting!May be finally we could use: (@c:FlightPlanWaypointFrequency...?Jan"Beatus ille qui procul negotiis..."

Share this post


Link to post
Share on other sites

Yes correct. BTW, this variable is not used in the GPS and so is not supported by MSFS.cheers,nick

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