我有一個簡單的測試@Testpublic void utf16SizeTest() throws Exception { final String test = "п"; // 'п' = U+043F according to unicode table // 43F to binary = 0100 0011 1111 (length is 11) // ADD '0' so length should be = 16 // 0000 0100 0011 1111 // 00000100(2) 00111111(2) // 4(10) 63(10) final byte[] bytes = test.getBytes("UTF-16"); for (byte aByte : bytes) { System.out.println(aByte); }}如您所見,我首先將'п'轉換為二進制,然后在時添加盡可能多的空位length != 16。期望輸出將是 4 , 63但是實際的是:-2-1463我究竟做錯了什么?
添加回答
舉報
0/150
提交
取消