Disco.Services.DocumentUniqueIdentifierExtensions.TryBinaryC21Encode C# (CSharp) Method

TryBinaryC21Encode() public static method

public static TryBinaryC21Encode ( string Data, byte &Result ) : bool
Data string
Result byte
return bool
        public static bool TryBinaryC21Encode(string Data, out byte[] Result)
        {
            // byte[0] = XXYY YYYY
            // byte[1] = YYYY YYYY
            //              X = 10 = C21 encoded
            //              Y = number component
            // byte[2] = AAAA ABBB
            // byte[3] = BBCC CCCD
            //              A,B,C = character component in
            //                      alpha encoded format

            short number;
            byte[] chars;
            if (Data.Length == 7 &&
                short.TryParse(Data.Substring(3), out number) &&
                number <= 9999 &&
                TryBinaryAlphaEncode(Data.Substring(0, 3), out chars))
            {
                Result = new byte[4];
                Result[0] = (byte)(0x80 | (number >> 8));
                Result[1] = (byte)number;
                Result[2] = chars[1];
                Result[3] = chars[2];
                return true;
            }

            Result = null;
            return false;
        }