Chinaunix首页 | 论坛 | 博客

acc

  • 博客访问: 791616
  • 博文数量: 170
  • 博客积分: 7011
  • 博客等级: 少将
  • 技术积分: 1660
  • 用 户 组: 普通用户
  • 注册时间: 2006-07-31 12:02
文章分类

全部博文(170)

文章存档

2014年(7)

2010年(2)

2009年(62)

2008年(25)

2007年(67)

2006年(7)

我的朋友

分类: Java

2009-01-18 11:16:40

代码:
 

import java.io.UnsupportedEncodingException;
public class T {
 public static void main(String[] args) throws UnsupportedEncodingException {
  t1();//ASCII转换为字符串

  t2();//字符串转换为ASCII码

 }
 public static void t1(){//ASCII转换为字符串

  String s="22307 35806 24555 20048";//ASCII码

  String[]chars=s.split(" ");
  System.out.println("ASCII 汉字 \n----------------------");
        for(int i=0;i<chars.length;i++){
            System.out.println(chars[i]+" "+(char)Integer.parseInt(chars[i]));
        }
 }
 public static void t2(){//字符串转换为ASCII码

  String s="新年快乐!";//字符串

  char[]chars=s.toCharArray(); //把字符中转换为字符数组

  System.out.println("\n\n汉字 ASCII\n----------------------");
  for(int i=0;i<chars.length;i++){//输出结果

         System.out.println(" "+chars[i]+" "+(int)chars[i]);
        }
 }
}

 

输出结果:

ASCII 汉字
----------------------
22307 圣
35806 诞
24555 快
20048 乐

汉字 ASCII
----------------------
 新 26032
 年 24180
 快 24555
 乐 20048
 ! 65281

 

准备做个小应用程序由汉字输出ASCII码,敬请期待。
使用此种方式可以给别人发ASCII码或者二进制、八进制、十六进制码,然后给他说:要想知道我的意思,请解码。
阅读(27298) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~