获取数据到字节-位的显示

  // Int32 num1 = 4;
            //long num1 = 4;
            Int64 num1 = 4;
 
 
 
            num1 = num1 << 1;//右移动
 
 
            byte[] bs = BitConverter.GetBytes(num1);
 
            BitArray arr = new BitArray(bs);
 
            //设置第四位为打开状态
            //arr[4] = true;
           
 
            var sb = new StringBuilder();
            for (int i = arr.Length-1; i >=0; i--)
            {
                if (arr[i] == true )
                {
                    sb.Append("1");
                }
                else
                {
                    sb.Append("0");
                }
            }
 
           
 
           
 
            Console.WriteLine(string.Format("Length is  :{0}",arr.Length));
            Console.WriteLine(sb.ToString());
 
 
 
 
            Console.WriteLine(Convert.ToInt64(sb.ToString(),2));
            Console.ReadKey();
posted @ 2014-12-31 13:59  特洛伊-Micro  阅读(221)  评论(0编辑  收藏  举报