File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes How to Decode a 7bit encoded hex string Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to Decode a 7bit encoded hex string" Watch "How to Decode a 7bit encoded hex string" New topic
Author

How to Decode a 7bit encoded hex string

Rishi Tyagi
Ranch Hand

Joined: Feb 14, 2002
Posts: 100
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

Joined: Feb 14, 2002
Posts: 100
What happened,
Out of so many java guru's no body responded for the problem.

Regs,
Rishi
Lewin Chan
Ranch Hand

Joined: Oct 10, 2001
Posts: 214
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 ?


I have no java certifications. This makes me a bad programmer. Ignore my post.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to Decode a 7bit encoded hex string
 
Similar Threads
help me
Weird unicode translation problem
August Newsletter Puzzle
how to generate a unique number
To Hex String and back...