public static void ShiftLeft(this BitArray bits) { bool first = bits.Bit(1); //guardar el primero for (var i = 2; i <= bits.Length; i++) { bits.Bit(i - 1, bits.Bit(i)); //recorre a la izquierda } bits.Bit(bits.Length, first); }
public static void ShiftRight(this BitArray bits) { bool last = bits.Bit(bits.Length); //guardar el ultimo for (var i = bits.Length; i > 1; i--) { bits.Bit(i, bits.Bit(i - 1)); //recorre a la derecha } bits.Bit(1, last); }
public static BitArray Concat(this BitArray bits, BitArray back) { var toReturn = new BitArray(bits.Length + back.Length); for (var i = 1; i <= toReturn.Length; i++) { if (i <= bits.Length) { toReturn.Bit(i, bits.Bit(i)); } else { toReturn.Bit(i, back.Bit(i - bits.Length)); } } return(toReturn); }
public static string Print(this BitArray bits, int group = 4) { var builder = new StringBuilder(); string append; for (var i = 1; i <= bits.Length; i++) { append = bits.Bit(i) ? "1" : "0"; //imprime 0 y 1 y no true y false builder.AppendFormat("{0}", append); if (i % group == 0) { builder.Append(" "); } } return(builder.ToString()); }