`

java ascii

    博客分类:
  • Java
 
阅读更多

import org.junit.Test;

public class byte2ascii {
	public static char convertChar1(byte b) {
		return (char) b;
	}

	public static char convertChar2(byte b) {
		return (char) ((0xff & b));
	}

	public static char convertChar3(byte b) {
		return (char) ((0 | b));
	}

	@Test
	public void test() {
		byte b = 65;
		System.out.println(convertChar1(b));
		System.out.println(convertChar2(b));
		System.out.println(convertChar3(b));
	}
	
	// 打印ascii码
	@Test
	public void printCode(){
	      for(byte b=0;b>=0 && b<128;b++){
	          System.out.print("十进制数: "+ b + "  |  ");
	          System.out.print("八进制数: "+ Integer.toOctalString(b) + "  |  ");
	          System.out.print("十六进制数: "+ Integer.toHexString(b) + "  |  ");
	          System.out.print("ASCII字符: "+(char)b);
	          System.out.println();  
	       }
	}
}
 
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics