-2

Various reverse-engineered versions of the allocation algorithmsused by different countries to allocate 24-bit ICAO addresses based on the aircraft registration These were worked out by looking at the allocation patterns and working backwards to an algorithm that generates that pattern,spot-checking aircraft to see if it worked. YMMV.

    registration_from_hexid = (function () {
    // hide the guts in a closure

    var limited_alphabet = "ABCDEFGHJKLMNPQRSTUVWXYZ"; // 24 chars; no I,O
    var full_alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";  // 26 chars



  // handles 3-letter suffixes assigned with a regular pattern
  //
  // start: first hexid of range
  // s1: major stride (interval between different first letters)
  // s2: minor stride (interval between different second letters)
  // prefix: the registration prefix
  //
  // optionally:
  //   alphabet: the alphabet to use (defaults full_alphabet)
  //   first: the suffix to use at the start of the range (default: AAA)
  //   last: the last valid suffix in the range (default: ZZZ)

     var stride_mappings = [
     { start: 0x008011, s1: 26*26, s2: 26, prefix: "ZS-" },

     { start: 0x390000, s1: 1024, s2:  32, prefix: "F-G" },
     { start: 0x398000, s1: 1024, s2:  32, prefix: "F-H" },

     { start: 0x3C4421, s1: 1024,  s2: 32, prefix: "D-A", first: 
     'AAA', last: 'OZZ' },
     { start: 0x3C0001, s1: 26*26, s2: 26, prefix: "D-A", first: 
     'PAA', last: 'ZZZ' },
     { start: 0x3C8421, s1: 1024,  s2: 32, prefix: "D-B", first: 
     'AAA', last: 'OZZ' },
     { start: 0x3C2001, s1: 26*26, s2: 26, prefix: "D-B", first: 
    'PAA', last: 'ZZZ' },
    { start: 0x3CC000, s1: 26*26, s2: 26, prefix: "D-C" },


{ start: 0x3D04A8, s1: 26*26, s2: 26, prefix: "D-E" },


 { start: 0x3D4950, s1: 26*26, s2: 26, prefix: "D-F" },
        { start: 0x3D8DF8, s1: 26*26, s2: 26, prefix: "D-G" },
        { start: 0x3DD2A0, s1: 26*26, s2: 26, prefix: "D-H" },
        { start: 0x3E1748, s1: 26*26, s2: 26, prefix: "D-I" },

        { start: 0x448421, s1: 1024,  s2: 32, prefix: "OO-" },
        { start: 0x458421, s1: 1024,  s2: 32, prefix: "OY-" },
        { start: 0x460000, s1: 26*26, s2: 26, prefix: "OH-" },
        { start: 0x468421, s1: 1024,  s2: 32, prefix: "SX-" },
        { start: 0x490421, s1: 1024,  s2: 32, prefix: "CS-" },
        { start: 0x4A0421, s1: 1024,  s2: 32, prefix: "YR-" },
        { start: 0x4B8421, s1: 1024,  s2: 32, prefix: "TC-" },
        { start: 0x740421, s1: 1024,  s2: 32, prefix: "JY-" },
        { start: 0x760421, s1: 1024,  s2: 32, prefix: "AP-" },
        { start: 0x768421, s1: 1024,  s2: 32, prefix: "9V-" },
        { start: 0x778421, s1: 1024,  s2: 32, prefix: "YK-" },
        { start: 0x7C0000, s1: 1296,  s2: 36, prefix: "VH-" },
        { start: 0xC00001, s1: 26*26, s2: 26, prefix: "C-F" },
        { start: 0xC044A9, s1: 26*26, s2: 26, prefix: "C-G" },
        { start: 0xE01041, s1: 4096,  s2: 64, prefix: "LV-" }
        ];
        function lookup(hexid) {
        var hexid = +("0x" + hexid);

        reg = n_reg(hexid);
        if (reg)
        return reg;

        reg = ja_reg(hexid);
        if (reg)
        return reg;

        reg = hl_reg(hexid);
        if (reg)
        return reg;

        reg = numeric_reg(hexid);
        if (reg)
        return reg;

        reg = stride_reg(hexid);
        if (reg)
        return reg;

        return null;
        }

         function stride_reg(hexid) {
         // try the mappings in stride_mappings
         var i;
         for (i = 0; i < stride_mappings.length; ++i) {
         var mapping = stride_mappings[i];
         if (hexid < mapping.start || hexid > mapping.end)
         continue;

         var offset = hexid - mapping.start + mapping.offset;

         var i1 = Math.floor(offset / mapping.s1);
         offset = offset % mapping.s1;
         var i2 = Math.floor(offset / mapping.s2);
         offset = offset % mapping.s2;
         var i3 = offset;

         if (i1 < 0 || i1 >= mapping.alphabet.length ||
         i2 < 0 || i2 >= mapping.alphabet.length ||
         i3 < 0 || i3 >= mapping.alphabet.length)
         continue;

         return mapping.prefix + mapping.alphabet.charAt(i1) + 
         mapping.alphabet.charAt(i2) + mapping.alphabet.charAt(i3);
         }

        // nothing
        return null;
        }


        // US N-numbers
        //

        function n_letters(rem) {
        if (rem == 0)
        return "";

        --rem;
        return limited_alphabet.charAt(Math.floor(rem / 25)) + 
        n_letter(rem % 25);
        }

        function n_letter(rem) {
        if (rem == 0)
        return "";

       --rem;
      return limited_alphabet.charAt(rem);


      function n_reg(hexid) {
      var offset = hexid - 0xA00001;
      if (offset < 0 || offset >= 915399) {
      return null;
      }

     var digit1 = Math.floor(offset / 101711) + 1;
     var reg = "N" + digit1;
     offset = offset % 101711;
     if (offset <= 600) {
     // Na, NaA .. NaZ, NaAA .. NaZZ
     return reg + n_letters(offset);
     }

     // Na0* .. Na9*
     offset -= 601;

     var digit2 = Math.floor(offset / 10111);
     reg += digit2;
     offset = offset % 10111;

     if (offset <= 600) {
     // Nab, NabA..NabZ, NabAA..NabZZ
     return reg + n_letters(offset);
     }

     // Nab0* .. Nab9*
     offset -= 601;

     var digit3 = Math.floor(offset / 951);
     reg += digit3;
     offset = offset % 951;

     if (offset <= 600) {
     // Nabc, NabcA .. NabcZ, NabcAA .. NabcZZ
     return reg + n_letters(offset);
     }

                // Nabc0* .. Nabc9*
                offset -= 601;

                var digit4 = Math.floor(offset / 35);
                reg += digit4.toFixed(0);
      offset = offset % 35;

      if (offset <= 24) {
      // Nabcd, NabcdA .. NabcdZ
      return reg + n_letter(offset);
      }

      // Nabcd0 .. Nabcd9
      offset -= 25;
      return reg + offset.toFixed

      (0);
8
  • No one understands what you're asking, please clarify Nov 23, 2018 at 9:16
  • I have a list of codes which I don't have the hex value or binary value. I was trying to work out what the formula is , as you can see some of the codes have a mixture of letters and numbers. So how does 432B get converted to Hex - A52AA5
    – Mr North
    Nov 23, 2018 at 9:44
  • @MrNorth So what I understand (but maybe I am wrong) is that you are looking for a single Excel formula that will convert the 4 codes in the Hex equivalent??
    – Peter K.
    Nov 23, 2018 at 11:43
  • yes that is correct
    – Mr North
    Nov 23, 2018 at 12:51
  • Each code has the letter N at the start , not sure if that is relevant ? N1 , N2 , N432B , N678XX
    – Mr North
    Nov 23, 2018 at 13:05

2 Answers 2

1

The mode s hex code is used in aerospace/navigation.
From wikipedia :

Mode S equipped aircraft are assigned a unique ICAO 24-bit address or (informally) Mode-S "hex code" upon national registration and this address becomes a part of the aircraft's Certificate of Registration. Normally, the address is never changed, however, the transponders are reprogrammable and, occasionally, are moved from one aircraft to another (presumably for operational or cost purposes), either by maintenance or by changing the appropriate entry in the aircraft's Flight management system.

There are 16,777,214 (224-2) unique ICAO 24-bit addresses (hex codes) available.[4][5] The ICAO 24-bit address can be represented in three digital formats: hexadecimal, octal, and binary. These addresses are used to provide a unique identity normally allocated to an individual aircraft or registration.

You can find the aircraft just be googling each mode s hex code, e.g. for the first one: https://www.radarbox24.com/data/mode-s/A00001#1068536488.

The N-code is the Aircraft Registration code. Again, from Wikipedia:

In the United States, the registration number is commonly referred to as an "N" number, because all aircraft registered there have a number starting with the letter N. An alphanumeric system is used because of the large numbers of aircraft registered in the United States. An N-number begins with a run of one or more numeric digits, may end with one or two alphabetic letters, may only consist of one to five characters in total, and must start with a digit other than zero.

I do not think there is any mathematical or logical relationship between the mode s hex and the aircraft registration code !!

5
  • There is a formula used, but I have not been able to research it. Had hoped a formula guru might have an answer
    – Mr North
    Nov 23, 2018 at 15:38
  • @MrNorth Do you have a source that confirms that there is a formula? I would seriously doubt that such formula exists. The FAA assigns the registration codes in the USA and has to choose a mode s hex code from a block that is made available by the ICAO for the US. It is indeed so that the Gulfstream owned by the FAA with registration number N1 has also the first mode s hex code from the block. But if you look at N2, ,the ICAO address is completely different. registry.faa.gov/aircraftinquiry/NNum_Results.aspx?NNumbertxt=2
    – Peter K.
    Nov 23, 2018 at 15:53
  • i have attached a javascript file converted to text showing the formulas for a list of countries. and some form of formulas.
    – Mr North
    Nov 23, 2018 at 16:07
  • I only looked at the US, as the first 3 are registered with the FAA. The 4th I didn't find (if you say it starts with an N as well, there must be a typo because that registration number does not exist). So maybe other countries do it differently.
    – Peter K.
    Nov 23, 2018 at 16:31
  • I have just added the javascript code , there is the formula for n number in hte text
    – Mr North
    Nov 23, 2018 at 16:40
0

The algorithms used by several different countries to map between ICAO/Mode S code and registration have been reverse engineered. The current, best description of those algorithms is probably this code that is part of the web front-end used by ADS-B Exchange:

https://github.com/wiedehopf/tar1090/blob/master/html/registrations.js (or here's a link to version that is current at the time of this answer's writing)

Here's the top-level function that handles Mode S codes in the United States' ranges:

    function n_reg(hexid) {
        let offset = hexid - 0xA00001;
        if (offset < 0 || offset >= 915399) {
            return null;
        }

        let digit1 = Math.floor(offset / 101711) + 1;
        let reg = "N" + digit1;
        offset = offset % 101711;
        if (offset <= 600) {
            // Na, NaA .. NaZ, NaAA .. NaZZ
            return reg + n_letters(offset);
        }

        // Na0* .. Na9*
        offset -= 601;

        let digit2 = Math.floor(offset / 10111);
        reg += digit2;
        offset = offset % 10111;

        if (offset <= 600) {
            // Nab, NabA..NabZ, NabAA..NabZZ
            return reg + n_letters(offset);
        }

        // Nab0* .. Nab9*
        offset -= 601;

        let digit3 = Math.floor(offset / 951);
        reg += digit3;
        offset = offset % 951;

        if (offset <= 600) {
            // Nabc, NabcA .. NabcZ, NabcAA .. NabcZZ
            return reg + n_letters(offset);
        }

        // Nabc0* .. Nabc9*
        offset -= 601;

        let digit4 = Math.floor(offset / 35);
        reg += digit4.toFixed(0);
        offset = offset % 35;

        if (offset <= 24) {
            // Nabcd, NabcdA .. NabcdZ
            return reg + n_letter(offset);
        }

        // Nabcd0 .. Nabcd9
        offset -= 25;
        return reg + offset.toFixed(0);
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.