在下面的代码片段考虑与评论等同安定使用0xff,澄清需要
1. private static String ipToText(byte[] ip) {
2. StringBuffer result = new StringBuffer();
3.
4. for (int i = 0; i < ip.length; i++) {
5. if (i > 0)
6. result.append(".");
7.
8. result.append(ip[i]); // compare with result.append(0xff & ip[i]);
9. }
10.
11. return result.toString();
12. }
.equals()
测试替换第8行确认加入0xff
不会改变任何东西。是否有这个面具适用的原因?
我不确定,但看起来像转换为无符号字节。 – Osw 2012-03-30 20:23:58