怎样读取一个byte中的每个bit的值
一个byte有8个bit怎样读取到每一个bit的值如
byte值(01000100)怎样读到第三个的值

解决方案 »

  1.   

    int GetBit(byte by,int i)
    {
    if(i<1||i>8)
      throw new Exception();
    return (by<<(i-1))>>7;
    }
      

  2.   

    按位与操作 比如读a的第5位,就是取 a & 32,如果是0,那这位就是0,如果非0,这位就是1。
      

  3.   

    new BitArray(new byte[]{0xFF})[??];
      

  4.   

    byte[] _Value = new byte[1];
                    BittArray.CopyTo(_Value, 0);
      

  5.   

    按位与:&
    byte a=(01000100)
    int i=a&4       4=(00000100)if(i>0)
    {
    标红位就是1
    }
    esle
    {
    标红位就是0
    }
      

  6.   

            public static bool GetBits(uint num, int bit)
            {
                uint v = bit == 0 ? 1 : 2u << (bit - 1);
                return ((num & v) != 0);
            }
      

  7.   

      
    public void WritebyteCount(int start, int lowOffset, BitArray ba)
            {
                byte[] bytes = new byte[1];
                ba.CopyTo(bytes,0);
                byte bt=bytes[0];
                WriteByte(start,bt);
            } public void WriteByte(int start, byte byteValue)
            {
                FileStream fileStream = File.Open(fileName, FileMode.Open);
                fileStream.Seek(start, SeekOrigin.Begin);
                using (BinaryWriter binWriter = new BinaryWriter(fileStream))
                {
                    binWriter.Write(byteValue);
                    binWriter.Close();
                }            fileStream.Close();
            }byteValue的值为1,3是在bin里是01,其他值在bin为什么是 03
    这是为什么啊?