The simFlight Network Forums

# Factoring an FS2002 value....

## Recommended Posts

Hello, I've got a problem getting a value out of FS2002 via FSUIPC.

According to the list, 0580 contains the heading, but as hdg * 360 / (65536 * 65536). Looking at FS Interrogate though, I see a value of -36869590 and a heading of 356.9

Well, I've played and played with that formula and those numbers, and I just can't see any way to make that formula convert one to t'other :-(

Just for starters, with no addition or subtraction in it, how does it even go from negative to positive??

Richard

##### Share on other sites

According to the list, 0580 contains the heading, but as hdg * 360 / (65536 * 65536). Looking at FS Interrogate though, I see a value of -36869590 and a heading of 356.9

Well, I've played and played with that formula and those numbers, and I just can't see any way to make that formula convert one to t'other :-(

Just for starters, with no addition or subtraction in it, how does it even go from negative to positive??

Taking the last question frst, whether it is negative or positive is the way you look at it. It is a 32 bit value. In hexadecimal it is FDCD6A2A, As a signed value it would be the -36869590 you quote. But if you view it as unsigned it is a much larger positive number. FSInterrogate can show you both interpretations if you like. In computers values are like that -- you can treat them in many different ways. In this case you should really be treating is as an undgned, and therefore positive, 32-bit integer.

However, whether you want to treat it as signed or unsigned is really irrelevant in this case -- as far as the Heading is concerned a value of -10 is the same as +350. It's a circle after all with no beginning, no end. If the value you arrive at is outside the range 0-359, just adjust it by 360's until it looks right.

So, according to my calculator

(-36869590 * 360) / (65536 * 65536) = -3.09

which is the very same identical heading as +356.91. If you don't believe that go look at a compass rose and think about it. Just think anti-clockwise for negative, clockwise for positive.

If you prefer just to deal in positive numbers, just read the heading into an UNSIGNED integer variable and do the calculations on that. You'll get 356.9 then without messing with adding 360.

All this method of storing compass values (which is an FS convention) is designed to do is to allow the most accurate value possible to be stored in the 32 bits available. So, the biggest possible direction (359.99999... degrees) occupies all of the bits (hex FFFFFFFF). Add 1 to this and you'd get the value representing 360 degrees which is the same as 0 degrees, and zero in the 32 bits.

So, a 1 in the (non-existent) 33rd bit represents the non-existent value 360. The divisor in the conversion, 65536*65536 is actually just a 1 in that 33rd bit (hex 100000000), but you cannot store that value in a normal 32 bit integer, which is why it is easier to divide by 65536 twice.

I suppose I've succeeded in confusing you more by now. But just think about it a while. It really is very simple, and it works.

Pete

##### Share on other sites

I can offer some help on this one. If you call anything VB related, help!

Public Property Get heading_value() As Long

Dim succ As Boolean, offset As Long, Num As Long

offset = &H0580

End Property

where mavrheading is a global private Long

works absolutly fine.

If you are still worried about + & - then * by -1

If I have learnt anything from Pete its this, dont worry or think about it to hard. JUST DO IT............

##### Share on other sites

Thanks very much guys. I must have looked at that -3.09 a dozen times without it 'clicking' that it was the difference between the displayed heading and 360 !!

Now for the embarrassing confession...... I am by training a Merchant Navy navigating officer, so all that compass stuff is supposed to be second nature !

Richard

## Create an account

Register a new account