if (hibyte == 0) {
for (int i = count ; i-- > 0 ;) {
value[i] = (char) (ascii[i + offset] & 0xff);
}
} else {
hibyte <<= 8;
for (int i = count ; i-- > 0 ;) {
value[i] = (char) (hibyte | (ascii[i + offset] & 0xff));
}
}
Note:
int hibyte 为Unicode码高8位
char value[] 为字符型数组
int count 为字符数组长度,即char value = new char[count]求解该段代码位操作的含义
for (int i = count ; i-- > 0 ;) {
value[i] = (char) (ascii[i + offset] & 0xff);
}
} else {
hibyte <<= 8;
for (int i = count ; i-- > 0 ;) {
value[i] = (char) (hibyte | (ascii[i + offset] & 0xff));
}
}
Note:
int hibyte 为Unicode码高8位
char value[] 为字符型数组
int count 为字符数组长度,即char value = new char[count]求解该段代码位操作的含义
ascii[i + offset] & 0xff该句完成将ascii[i + offset]的高8位请0
hibyte <<= 8;将高8位右移8位
hibyte | (ascii[i + offset] & 0xff)
该句在hibyte完成右移,ascii[i + offset]高8位被清0之后,其实相当于
hibyte + (ascii[i + offset] & 0xff)