public static void main(String[] args) {
String str="我";
char[] ch=str.toCharArray();
byte[] by =charToByte(ch[0]);
for (int i = 0; i < by.length; i++) {
System.out.println(by[i]);
}
}
public static byte[] charToByte(char c) {
byte[] b = new byte[2];
b[0] = (byte) ((c & 0xFF00) >> 8);
b[1] = (byte) (c & 0xFF);
return b;
}
public static char byteToChar(byte[] b) {
char c = (char) (((b[0] & 0xFF) << 8) | (b[1] & 0xFF));
return c;
}
char与byte转换
最新推荐文章于 2023-06-21 16:26:49 发布