java 好像都是网络序。 但是 char a[] = {'a'};
ByteBuffer b = ByteBuffer.allocate(2);
b.putChar(a[0]);
b.flip();
String s = new String("a".getBytes()); System.out.println(Arrays.toString(s.getBytes("unicode")));
System.out.println(Arrays.toString(b.array()));结果为:
[-1, -2, 97, 0]
[0, 97]为什么string的 getBytes是 97 , 0 。而 ByteBuffer 的底层bytes是 0,97呢。换一个 汉字“天”结果是
[-1, -2, 41, 89]
[89, 41]都是相反的?
ByteBuffer b = ByteBuffer.allocate(2);
b.putChar(a[0]);
b.flip();
String s = new String("a".getBytes()); System.out.println(Arrays.toString(s.getBytes("unicode")));
System.out.println(Arrays.toString(b.array()));结果为:
[-1, -2, 97, 0]
[0, 97]为什么string的 getBytes是 97 , 0 。而 ByteBuffer 的底层bytes是 0,97呢。换一个 汉字“天”结果是
[-1, -2, 41, 89]
[89, 41]都是相反的?
string的 getBytes 是 主机序吗?