原文:
If you are converting from a byte value b to a char and you don’t want sign
extension, you must use a bit mask to suppress it. This is a common idiom, so no
comment is necessary:
char c = (char) (b & 0xff);
没有get到 sign extension的含义!以及为什么这么做就没有sign extension
首先char是16位 byte是8位 byte有负数形式 char没有 如果直接做移位 负数的byte会直接根据首位的符号位1直接扩展 变成111111111xxxxxx形式 而做位与则不会出现这个问题