Page 1 of 1

BCD16

Posted: 10 May 2009, 16:40
by kungfuman
Hi folks,

Anyone know how to encode a vhf frequency into the sort of format that an FS9 BGL file would use?

I am lead to believe the following:

Frequencies of the form 1ab.cd MHz are stored as "abcd" in BCD16 format.

So AFAIK, this means that 126.900 MHz would be stored as 0x2690, or

0010 0110 1001 0000

However, the space assigned is a dword, not a word, so will the additional bits just be 16 more zeros on the right?

Also, are frequencies with three decimal places truncated to only 2 d.p. (that being all that is necessary)?

Cheers,

Dan "raised by wolves"

Posted: 10 May 2009, 17:54
by VulcanDriver
:shock:

Posted: 10 May 2009, 18:03
by kungfuman
VulcanDriver wrote::shock:
:lol: :lol: :lol:

Well, this is the tech forum, right?

Posted: 10 May 2009, 18:14
by BASys
Hi Folks

kungfuman -
Please see - FSDeveloper - Wiki - Variables - Formats - Encoding - Binary
It's a WIP, but might cover what you're after.

Regarding spaces, dots, hyphens etc.
I think they're only included for ease of reading.
AIUI there should be none, it's just the binary value.
e.g. 0011011000100101

HTH
ATB
Paul

Posted: 10 May 2009, 18:44
by kungfuman
Thanks Paul,

That confirms my understanding about BCD16 :wink:

Posted: 12 May 2009, 09:21
by kungfuman
Not that I expect there to much interest here, but for what it's worth I have found that the frequencies are simply encoded as an int32, the value of which being the frequency in Hz.

If you're doing this for the first time and need more explanation, read on.

To find out what the content of the "int32" would be for 123.45 MHz, take 123.45 and multiply by 1,000,000 (1 million), then convert into the base-16 value (aka hexadecimal, or just hex): 075bb290. This is then easily translated into binary, with each digit representing four "bits" (aka a "nibble"):

Hex -> Binary
0 ----> 0000
7 ----> 0111
5 ----> 0101
b ----> 1011
b ----> 1011
2 ----> 0010
9 ----> 1001
0 ----> 0000

The int32 will store this binary number
0000 0111 0101 1011 1011 0010 1001 0000 (the spaces are used here only for ease of presentation)
by splitting the 32 digits into 4 groups, each one consisting of 8 digits (these digits are the "bits", and the groups are the "bytes"). The first group stored in the int32 (the first byte) is the group representing the least significant part of the number (the 1s, 2s, 4s, 8s, 16s, 32s, 64s and 128s): 10010000
Notice that these are the last 8 digits on the right. The second byte is the next 8 digits to the left of the first byte: 10110010
And so on.

Maybe of help to someone one day, you never know!

Posted: 12 May 2009, 12:14
by Garysb
Kungfuman
Can I suggest therapy ! :lol: :lol: :lol: :lol: :shock:


Cheers


Gary

Posted: 12 May 2009, 12:38
by kungfuman
Can you recommend someone? The NHS just gave me pills...

Posted: 12 May 2009, 14:42
by petebramley
I recommend a large glass of Laphroaig (water to taste). I have found this to be the cure to all ills
:D :D :D :D

Pete

Posted: 12 May 2009, 16:22
by VulcanDriver
kungfuman wrote:
VulcanDriver wrote::shock:
:lol: :lol: :lol:

Well, this is the tech forum, right?
It brought back all the horrors of my IT university course!!

Posted: 12 May 2009, 19:00
by kungfuman
For some reason the little smiley looking plaintively out of the page with shocked eyes had me in stitches. I really do need help!

Probably the best reply I've ever had to a post of mine...

Posted: 13 May 2009, 01:30
by ricktk
All I can say is a Dalwhinnie solved my headache over this thread! It all became clear. (Hic) Well, maybe not, but it did make me feel better. Cheers :D