日期:2014-05-18 浏览次数:20845 次
static bool GetBit(int data, int bit) { int test = 1 << (bit - 1); return (data | test) == data; }
------解决方案--------------------
System.Collections.BitArray,或者BitConverter.ToInt64/ToUInt64然后用位运算来取值
------解决方案--------------------
namespace ConsoleApplication6 { class Program { static byte[] bs = { 231, 132, 120, 97, 65, 0, 0, 0 }; static void Main(string[] args) { ulong i64 = BitConverter.ToUInt64(bs, 0); Console.WriteLine("{0:x}", getNumber(i64, 0, 6)); //0-6位 Console.WriteLine("{0:x}", getNumber(i64, 6, 2)); //7-8位 //..... Console.ReadLine(); } static ulong getNumber(ulong i64, int start, int len) { i64 = i64 << 64 - start - len >> 64 - len; return i64; } } }