private static byte changeOneByte(byte b){ int buff=0; //一个byte 占用8位 for(int j=0;j<8;j++){ //得到这一个buff[i]的二进制位 -->取反 int bit = (b>>j&1)==0?1:0; buff+=(1<<j)*bit; } byte result=(byte)buff; return result; } public static void main(String[] args) { User2 u2 = new User2(); byte result = u2.changeOneByte((byte) 22); System.out.println(result); }
-23
原文:http://www.cnblogs.com/cici-new/p/3647806.html