java 字符与ASCII码互转

时间:2018-02-24 14:31:27   收藏:0   阅读:3865

 

字符转对应ASCII码

// 方法一:将char强制转换为byte
char ch = ‘A‘;
byte byteAscii = (byte) ch;
System.out.println(byteAscii);

// 方法二:将char直接转化为int,其值就是字符的ascii
int byteAscii1 = (int) ch;
System.out.println(byteAscii1);

 

ASCII码转字符

// 直接int强制转换为char
int ascii = 65;
char ch1 = (char)ascii;
System.out.println(ch1);

 

原文:https://www.cnblogs.com/ooo0/p/8465237.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!