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
posted Jun 20, 2005 04:53:00
0
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.
subject: How to Decode a 7bit encoded hex string