C#6.0
华为调制解调器使用PDU进行USSD,我需要一个c#代码或任何库来将纯文本编码为PDU并将PDU解码为纯文本ex:* 222#==> 2A994C3602,反之亦然。感谢。
答案 0 :(得分:0)
public static string GetPDUString(string plainString)
{
var bytes = Encoding.Default.GetBytes(plainString);
var packedBytes = PduBitPacker.PackBytes(bytes);
var hexString = PduBitPacker.ConvertBytesToHex(packedBytes);
return hexString;
}
public static string GetPlainText(string pduString)
{
var packedBytes = PduBitPacker.ConvertHexToBytes(pduString);
var unpackedBytes = PduBitPacker.UnpackBytes(packedBytes);
return System.Text.Encoding.Default.GetString(unpackedBytes, 0, unpackedBytes.Length);
}