Click here to Skip to main content
12,348,946 members (71,822 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C#3.0 C#
Hello

I am doing project in C# to read SMS in PDU mode.
I got Stuck up while converting code from octet to string.
I have referred code on internet to decode the same.but some PDU is not been decoded correctly.

Code given below contains HextoOctet array containg octet numbers in array.

private string  OctetToString()
      {
          int adderbitcnt = 1;
 
          string first = "";
          string adder = "";
 

          int arrayindex = 0;
          #region Adder Table
          try
          {
              for (int loop = 0; loop <= HextoOctet.Count; loop++)
              {
                  if (loop == 0)
                  {
                      addertable.Add("0");
                      first = HextoOctet[0].Substring(1, 7);
                      //basetable.Add(first);
                  }
                  else
                  {
                      if (adderbitcnt == 8)
                      {
                          addertable.Add("0");
                          adderbitcnt = 1;
                      }
                      else
                      {
                          adder = HextoOctet[arrayindex].Substring(0, adderbitcnt);
                          addertable.Add(adder);
                          adderbitcnt++;
                          arrayindex++;
                      }
 
                  }
 
              }
          }
          catch (Exception ex) 
          { 
              //MessageBox.Show("Adder table exception caught");
          }
          #endregion

          #region basetable
          int arrayindex1 = 0;
          int startbase = 1;
          int basebitcount = 7;
          string baseinfo = "";
          try
          {
              for (int loop1 = 0; loop1 <= HextoOctet.Count; loop1++)
              {
                  if (startbase == 8)
                  {
                      startbase = 1;
                      basetable.Add("0");
                  }
                  else
                  {
                      baseinfo = "";
                      basebitcount = 8 - startbase;
                      baseinfo = HextoOctet[arrayindex1].Substring(startbase, basebitcount);
                      baseinfo.Trim();
                      basetable.Add(baseinfo);
                      //basebitcount--;
                      startbase++;
                      arrayindex1++;
                  }
                  //}
              }
          }
          catch (Exception ex) 
          { 
              //MessageBox.Show("Base table exception"); 
          }
          #endregion

 

          #region Merging AdderTable&BaseTable
          //string addtblInfo = "";
          //string basetblInfo = "";
          string DECSeptet = "";
          try
          {
              for (int merge = 0; merge < basetable.Count; merge++)
              {
                  if (addertable[merge] == "0")
                  {
                      DECSeptet = basetable[merge];
                      Mergedseptet.Add(DECSeptet);
                  }
                  else
                  {
                      DECSeptet = "0" + basetable[merge] + addertable[merge];
                      Mergedseptet.Add(DECSeptet);
                  }
              }
          }
          catch (Exception ex) 
          {
              //MessageBox.Show("Merging Exceptiion"); 
          }
          #endregion

 
          #region DECODEDTOSTRING
          string success = "";
          try
          {
              for (int decode = 0; decode < Mergedseptet.Count; decode++)
              {
                  long l = Convert.ToInt64(Mergedseptet[decode], 2);
                  int i = (int)l;
                  //--------------New Area
                  if (i == 26 || i == 28)
                  {
                      if (i == 26)
                      {
                          success += "4";
                      }
                      if (i == 28)
                      {
                          success += "8";
                      }
                  }
                  //New area
                  else
                  {
                      success += Convert.ToChar(i);
                  }
 
              }
              
              
              //txtMessage.Text = " DECODED MESSAGE =" + success;
          }
          catch (Exception ex) 
          { 
              //MessageBox.Show("Decode exception caught"); 
          }
 
          
          //OctettoSeptet.Clear();
          #endregion

          return success;
          success = "";
          HextoOctet.Clear();
          addertable.Clear();
          basetable.Clear();
          Mergedseptet.Clear();
 

      }

Please Guide me.
Thanks in advance.

Regards
Agd
Posted 5-Feb-13 1:11am
Edited 5-Feb-13 1:12am
Joezer BH38.6K
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160621.1 | Last Updated 5 Feb 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100