• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to Decode a 7bit encoded hex string

 
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I working on a application where input is 7bit encoded hex Strings(GSM 7-bit encoding).
For example "C8329BFD06" is the 7-bit encoded string of "Hello" and "41F1980C" is the 7-bit encoded hex string of "Abcd"

I need to decode this data into the original Ascii characters. For this i wrote a small script but it gives me junk characters.

Is there anybody who can help me to sortout the problem.

My script code is as follows:

public String decode7BitMsg(int msgLength,String msg)
{
String respMsg="";

try{
String binaryStr=hexToBinary(msg);
int n=binaryStr.length()/7;
if(binaryStr.length()%7>0)
{while(binaryStr.length()%7>0)
binaryStr +="0";
n++;
}
System.out.println("Binary String :"+binaryStr);

for(int i=0;i<n;i++)
{
String str="";
if(binaryStr.length()>7)
{
str=binaryStr.substring(0,7);
binaryStr=binaryStr.substring(7);
}
else
{
str=binaryStr;
}
str ="0"+str.trim();
int x=Integer.parseInt(str,2);
//x=x>>1;
respMsg += ""+(char)x;
}

}catch(Exception e){
System.out.println("error :"+e);
}

return respMsg;
}

public String hexToBinary(String hexString)
{
String binaryStr="";
int n=hexString.length();
if(n%2>0)
hexString +="0";
for(int i=0;i<n/2;i++)
{
String str="";
if(hexString.length()>2)
{
str=hexString.substring(0,2);
hexString=hexString.substring(2);
}
else
{
str=hexString;
if(str.length()<2)
str +="0";
}
binaryStr += Integer.toBinaryString(Integer.parseInt(str,16));

}

return binaryStr;
}

Regs,
Rishi Tyagi
 
Rishi Tyagi
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What happened,
Out of so many java guru's no body responded for the problem.

Regs,
Rishi
 
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
At the risk of sounding facetious, have you had a look at the javamail class
javax.mail.internet.MimeUtility.

Of course, I'm not so familiar with 7bit encoding, but wouldn't this do the trick ?
reply
    Bookmark Topic Watch Topic
  • New Topic