在java中,如果一个byte型的数x
要判断这个x的第8位是不是1,若是1则返回1,0返回0,怎么写这个函数啊..我用了移位不行啊...谢谢

解决方案 »

  1.   

    return (x & 128) == 128 ? 1 : 0
      

  2.   

    return (x&0x80) == 0x80 ? 1 : 0;
      

  3.   

    public boolean methodName(byte b) {
        return (b1 & (byte)1) == (byte)1;
    }
      

  4.   

    public boolean methodName(byte b) {
        return ((b1 & (byte)1) == (byte)1) ? 1 : 0;
    }
      

  5.   

    对不起,网络有点问题。
    public int methodName(byte b) {
        return ((b1 & (byte)1) == (byte)1) ? 1 : 0;
    }