Beispiel #1
0
        // 以 long numeric string 方式编码一个数字字符串
        // 算法可参考:
        // https://www.ipc.be/~/media/documents/public/operations/rfid/ipc%20rfid%20standard%20for%20test%20letters.pdf?la=en
        public static byte[] EncodeLongNumericString(string text)
        {
            if (text.Length < 9)
            {
                throw new ArgumentException($"用于编码的数字字符串不应短于 9 字符(但现在是 {text.Length} 字符)");
            }

            byte[] bytes = Compact.IntegerCompact(text);
            if (bytes.Length < 4)
            {
                throw new ArgumentException($"数字字符串编码后不应短于 4 bytes(但现在是 {bytes.Length} bytes)");
            }

            byte second = (byte)((((text.Length - 9) << 4) & (byte)0xf0) | ((bytes.Length - 4) & 0x0f));

            List <byte> results = new List <byte>();

            results.Add(0xfb);
            results.Add(second);
            results.AddRange(bytes);

            return(results.ToArray());
        }