Jump to content
The simFlight Network Forums

Read Heading value 0x580 have problem

Recommended Posts


when I read the Heading 0x580,Ican't get the correct value.can you help me .FS2004 show heading is 340 .

DWORD head;

if (!FSUIPC_Read(0x580, 4, &head, &dwResult)||!FSUIPC_Process())


int heading= head*360/(65536*65536);

Edit12->Text =heading;

i track into .found the value of head is 3730953 .so 3730953*360/(65536*65536)<0,program error.

Link to comment
Share on other sites

int heading= head*360/(65536*65536);


i track into .found the value of head is 3730953 .so 3730953*360/(65536*65536)<0,program error.

I'm not surprised, since all FS angular measures in fixed point fields are designed to achieve maximum resolution in the space available. To do this in a 32-bit value means the maximum value in 32 bits is used to provide 359.999999... degrees. You are multiplying a very large value by 360, so getting overflow.

Even if you did not get overflow, dividing a 32 bit integer by 65536 * 65536 is similar to shifting it downwards by 16 + 16 = 32 bits -- guaranteeing to leave you with nothing at all for your efforts!

All this is surely simple arithmetic, can you see?

Copy the value you read into a floating point variable, like a "double" first, THEN do your conversions! This applies to nearly all the fixed point values -- unless you want simple approximations (which you could get above by doing the arithmetic in a different order, e.g.

int heading = ((head/65536)*360)/65536;

That rounds down to the integer below. Of course it would be a better approximation if you rounded to the nearest integer instead, thus:

int heading = (((head/65536)*360) + 32768)/65536;



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.