i am trying to create a decoding PDU method FOR "GSM" modems (ussd messages) all works fine but i have an error that occues which says"index out of Bounds" ,even if i fix it in one place it occures in other places
i hope you can guide me to the solution of this problem
public static string PduDecode(byte[] bytes)
{
string result = string.Empty;
string[] mymessage = new string[(bytes.Length/2) +1];
int index = 0;
while (index < mymessage.Length - 1)
{
mymessage[index]= Convert.ToString(bytes[index], 2).PadLeft(8, '0');
index++;
}
mymessage[index] =string.Empty;
while (index >= 0)
{
if (!string.IsNullOrWhiteSpace(mymessage[index]))
{
mymessage[index] = mymessage[index].Substring(0, index+1);
mymessage[index]=mymessage[index].PadLeft(8, '0');
}
index--;
}
index = 0;
while (index < mymessage.Length-1)
{
mymessage[index] = Convert.ToInt32(mymessage[index], 2).ToString("X");
index++;
}
result =string.Join("",mymessage);
result=HexStringToString(result);
return result;
}