-----转自http://159357qq.iteye.com/blog/1694240
- public class TestCharToInt {
- /**
- * @param args
- * 把char字符型数字转成int数字,因为他们的ascii码值恰好相差48,
- * 因此把char型数字减去48得到int型数据,例如'4'转换成了4
- * '0'的ascii码是48
- */
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- char code;
- code = (char)('0' + 1554 % 10);
- System.out.println('4'-48);
- System.out.println(code);
- System.out.println((int)code);
- code = 4;
- System.out.println(0+Character.valueOf(code));
- System.out.println((char)(0));
- //强制转换,(取到低16位)4个字节的取低2个字节
- char char1=(char)4;
- System.out.println((char)('0'+char1));
- System.out.println(0+Character.valueOf((char)0));
- }
- }