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;
}