Jump to content
The simFlight Network Forums

Convert BCD to decimal for display [SOLVED]


Recommended Posts

Hello Mr. Dowson, I trust you had a good visit with your daughter. Welcome back! I need to be bailed out... again :(

OK, the short version:

I'm trying to use Lua script to display the XPDR feq on my GF-166. But I'm getting the raw BCD value. How do I convert a BCD value to decimal?

The long version:

I understand that offset x0354 is an unsigned 16bit word (two bytes). I understand that FS stores the value as a Binary Coded Decimal. I'd never heard of that so I Googled it.

I then conducted searches here and found that many people had the same problem I am.

I've tried searching through the forum at Luahub.com... nuthin.

You said in another post, something about "shifting the byes"... I don't know what that means and now, I can't find that post for reference.

I've set a GF button to set the XPDR to x1200. Which, GFConfig converts to "1200" for the display, but naturally when I use Lua I get 4608. FSUIPC changed the parameter of x1200 to 4608.

If I remember correctly, I read that the GFConfig software preferrs to "control" the modules and that it doesn't like to share.

On the same GF-166, I have a clock in one window and the XPDR in the other. I was using Lua script to run the clock and GFConfig to run the XPDR but FS kept crashing randomly. So I thought I'd try using Lua script to run the XPDR.

I'd appreciate any help you have to offer.

Link to comment
Share on other sites

Why is it... When I post here and bother you, I solve my own problem.

I kept trying to convert BCD to Decimal. I found a converter online and discovered it nothing more then DEC2HEX!!!

I found a DEC2HEX function for Lua.

So I solved the puzzle!

Until next time,

Link to comment
Share on other sites

I've set a GF button to set the XPDR to x1200. Which, GFConfig converts to "1200" for the display, but naturally when I use Lua I get 4608. FSUIPC changed the parameter of x1200 to 4608.

But since you want a string copy for display in any case it is easy, just use

string.format("%04X", value)

which will convert the number 0x1200 (or 4608) into the string "1200".

I found a DEC2HEX function for Lua.

So I solved the puzzle!

As short as the above solution?

Pete

Link to comment
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
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use. Guidelines Privacy Policy We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.