Shifting a BitArray

后端 未结 2 800
天涯浪人
天涯浪人 2021-01-27 06:23

I\'m currently trying to shift a BitArray while keeping its length. Since there\'s no built-in method I\'m struggling to build one but can\'t make it work, unfortunatly.

2条回答
  •  无人共我
    2021-01-27 06:36

    public static bool[] Left_shiftBitArray(bool[] Array, int count)
            {
                Array = BitArray_LRotat(Array, count);
                for (int i=Array.GetLength(0)-1; i>=(Array.GetLength(0)-count); i--)
                {
                    Array[i] = false;
                }
    
                return Array;
            }
    
            public static bool[] BitArray_LRotat(bool[] input, int x)
            {
                //bool [] temp= new bool[input.Length];
                bool[] final = new bool[input.Length];
                for (int i = input.Length; i > x; i--)
                {
                    final[i - x - 1] = input[i - 1];
                }
                for (int i = x; i > 0; i--)
                {
                    final[(input.Length) - i] = input[x - i];
                }
                return final;
            }
    

提交回复
热议问题