The simFlight Network Forums

# Friday Afternoon Blues

## Recommended Posts

OK It's Friday afternoon and my brain has clearly stopped working. I am reading the Alt Lo and Alt Hi fields to get altitude. Alt Hi is fine but I am doing something wrong for Alt Lo.

I have a value being returned of -1841823744 which I am treating as a double. If I calculate the low part by dividing this number by 65536*65536 and multiplying by 3.28084 I get -1.4066 but the answer I need is 1.87391 and this is being returned by FS Interrogate correctly

Is this field a 32 bit signed integer? A far as I can see it should always be zero or positive. :?

Any help much appreciated

##### Share on other sites

I am reading the Alt Lo and Alt Hi fields to get altitude. Alt Hi is fine but I am doing something wrong for Alt Lo.

In actual fact, the Alt is really just one 64-bit fixed point number. It is only represented in FSInterrogate version1 as Alt Hi and Lo because that program could not handle 64-bit fixed point.

I have a value being returned of -1841823744 which I am treating as a double

It cannot be negative, as the lower 32 bits of a 64-bit number has no sign bit -- the only sign bit in a 64-bit signed number is the one right at the top, which in your terms is in the Alt Hi part.

The number is unsigned, but it is a fraction and has the same sign as the high part, so after evaluation, if the high part is positive, you add it to it, if it is negative, you subtract it.

It is far easier if the language you are using supports 64-bit numbers (eg __int64 in C/C++).

If I calculate the low part by dividing this number by 65536*65536 and multiplying by 3.28084 I get -1.4066

Okay, in that case you are nearly there. Since it should have been treated as positive, you need to add that to the most positive number that fractional part in metres could hold, plus 1. Since that would be 1 metre, in feet your answer is 3.28084 - 1.4066 = 1.87424 ft.

Now you must add that to the feet from the high part, if that is positive, but subtract it from that if it is negative.

but the answer I need is 1.87391

One of you is approximating somewhere then, as that would make one metre equal to 3.28051 ft. However, it is close enough for normal purposes! ;-)

... and this is being returned by FS Interrogate correctly

Surely you are not still using FSInterrogate version 1? My last version of the SDK only provided an FSI file for FSInterrogate version 2, which is far superior.

Is this field a 32 bit signed integer? A far as I can see it should always be zero or positive. :?

Correct, it is never negative as it has no sign bit. It is the way you are interpreting it, not the nature of the number. It sounds like you are using that dreadful Visual Basic which doesn't bother to provide any support for unsigned numbers! :-(

Pete

##### Share on other sites

Thanks Pete No I am using version 2 of FS Interrogate but I did look at it in both versions

It sounds like you are using that dreadful Visual Basic which doesn't bother to provide any support for unsigned numbers!

Not exactly :D I use Visual Studio 2005 and I have signed and unsigned integers in both VB and C# :D :D

##### Share on other sites

Thanks Pete No I am using version 2 of FS Interrogate but I did look at it in both versions

But if you are using the correct FSI (version 2) and the FSI file I supplied, the Altitude display is shown as one 64-bit value not an Alt-Hi and Alt-Lo.

I use Visual Studio 2005 and I have signed and unsigned integers in both VB and C# :D :D

But in that case, if you have defined the variable you read "Alt Lo" into as unsigned, it is actually impossible for it to take on the negative value you show. Something is screwy somewhere!

Anyway, since you now have an even later development system than I do, why not move over to using 64-bit integers where they are appropriate, and make your life much easier?

Pete

##### Share on other sites

you are right. At the moment all my interfacing is in a separate dll and the code in there is a bit long in the tooth. I need to go and update it

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.