BCD16
BCD16
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"
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"
- VulcanDriver
- MAIW Staff
- Posts: 4575
- Joined: 11 Aug 2006, 20:58
- Version: FSX
- Location: EGHH
-
- Second Lieutenant
- Posts: 36
- Joined: 12 Aug 2006, 11:58
- Version: FSX
- Location: EGNL, Barrow-in-Furness, Cumbria, UK
- Contact:
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
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
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!
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!
- petebramley
- MAIW Developer
- Posts: 1545
- Joined: 17 Jun 2007, 16:05
- Version: P3D
- Location: EGBG
- VulcanDriver
- MAIW Staff
- Posts: 4575
- Joined: 11 Aug 2006, 20:58
- Version: FSX
- Location: EGHH