/* main initialization function. erase our cache too if needed */ public override void init(string binaryString, int bpc, int add) { base.init(binaryString, bpc, add); if (binaryString != null) { swp = null; byteArray = null; } }
public StringWithParity toStringWithParity(int add) { if (swp == null) { swp = calculateStringWithParity(Atoms, add); } return(swp); }
public StringWithParity(StringWithParity swp) { if (swp.st != null) { int len = swp.st.GetLength(0); this.st = new byte[len]; Array.Copy(swp.st, this.st, len); } if (swp.parity != null) { int len = swp.st.GetLength(0); this.parity = new bool[len]; Array.Copy(swp.parity, this.parity, len); } }
public static string stringWithParityToBinaryString(StringWithParity swp, int bpc, int add) { if (swp == null) { return(null); } StringBuilder sb = new StringBuilder(); byte [] data = swp.data; for (int i = 0; i < data.GetLength(0); i++) { bool parity = true; byte encodedChar = (byte)(Convert.ToByte(data[i]) - add); for (int j = 0; j < bpc - 1; j++) { if ((encodedChar & (1 << j)) != 0) { sb.Append('1'); parity = !parity; } else { sb.Append('0'); } } if (parity) { sb.Append('1'); } else { sb.Append('0'); } } return(sb.ToString()); }
public static bool IsNullOrEmpty(StringWithParity crcString) { return((crcString.st == null) || (crcString.parity == null)); }
public Variant(StringWithParity input, int bpc, int add) { init(input, bpc, add); }
/* initialization through StringWithParity */ public void init(StringWithParity input, int bpc, int add) { init(stringWithParityToBinaryString(input, bpc, add), bpc, add); }