首页 Soft PlugIn RAN乱 Dev开发 Info资料 English WAP 留言 登陆 注册
-
Posted by Yippee | 评论(0) | 引用(1) | 阅读2569次
Java str2bcd 压缩BCD编码

今天准备将SGIP用JAVA来写写。使用JBUILDER,测试WINXP/LINUX均通过,没有正式编码,只是测试了一下简单的发送接收 SOCKET。手机接收短信OK。

找了半天JAVA BCD编码资料,都是乱七八糟的,没有什么有用的东西,有个JAVA类库倒是提供STR2BCD,可是我又没有必要使用如此一个类库。因此还是自己写一下算了。比较弱智的写法。

public byte [] str2bcd(String str)
  {
    String s=str.toUpperCase();
    int ii=str.length();
    byte [] b=new byte[ii/2];
    for(int i=0,j=0;i<ii;i++,j++)
    {
      int i1,i2;
      if(s.charAt(i) -'A'>=0)
        i1=s.charAt(i) -'A'+10;
      else
        i1=s.charAt(i) -'0';
      if(s.charAt(i+1) -'A'>=0)
        i2 = s.charAt(i+1) - 'A' + 10;
      else
        i2 = s.charAt(i+1) - '0';

        b[j]=(byte)(i1*0x10+i2);
        i=i+1;
    }
    return b;
  }

public void printbytes(byte []b)
  {
    String str;
    for(int i=0;i<b.length;i++)
    {
      str= Integer.toHexString((int)(b[i]&0xff));
      if(str.length()==1)
        str="0"+str;
      System.out.print(str);
    }
  }

byte[] b;
String strOut = null;
if(strIn == null || (strIn.trim()).equals(""))
return strIn;
try{
b = strIn.getBytes("GBK");
strOut = new String(b,"ISO8859_1");
}catch(UnsupportedEncodingException e){ }
return strOut;
比起C#来真是麻烦多了 http://www.shengfang.org/blog/p/vsnetbcdstring.php

Jbuilder生成可执行文件 打包

To create an archive with the Archive Builder:
Open the project you wish to deploy.
Build the project to create the .class files, copy resources, and so on.
Choose File|New and select the Archive page.
Double-click the type of archive you want to run and complete the steps of the wizard.
Right-click the archive node in the project pane and choose Make to create the archive.

最好选择 Creating executables with the Native Executable Builder archive executable jar


字体:

Permanant URI永久地址 http://www.shengfang.org/blog/p/javabcd.php
Trackback URI引用地址 http://www.shengfang.org/blog/tb.php?tb_id=1120632632

2005年7月6日14:50星期三  [Dev开发] 追踪此文的RSS
提示:
此文还没有评论。

称呼:    登陆   注册
   不注册,但记住我的信息
邮件:
(非必须)
评论: [UBB代码帮助]
粗体 斜体 下划线 链接 水平线 引用



验证码: 请输入你看见的数字
关闭UBB      提交时自动将内容复制到剪贴板

公告
Fire and Motion!

统计信息
[Yippee]||[统计]||日志:1858
在线: 13||用户: 2577 [列表]
今日:394||到访:2886458
Rss:897736||评论:1605

最新日志

最新评论

友情链接

日历
2008 - 08
     12
3456789
10111213141516
17181920212223
24252627282930
31      

最新引用

搜索

归档

杂项
Get RSS Feed (Version 2.0)
Get Atom Feed (Version 0.3)
编码:  UTF-8