public void perm8_example() { var perm = Perm.Define <N8>((2, 3), (6, 7)); var bs1 = ((byte)0b10001101).ToBitString(); var bs2 = BitString.Parse("01001101"); var bs3 = bs1.Permute(perm); Claim.eq(bs2, bs3); }
public void pack_bistring() { var x = 0b111010010110011010111001110000100001101ul; var xbs = BitString.Parse("111010010110011010111001110000100001101"); var packed = xbs.Pack(0, 8); var joined = packed.TakeUInt64(); Claim.Equals(x, joined); }
/// <summary> /// Convert a postgresql bit to a System.Boolean. /// </summary> internal static Object ToBit(NpgsqlBackendTypeInfo TypeInfo, String BackendData, Int16 TypeSize, Int32 TypeModifier) { // Current tests seem to expect single-bit bitstrings to behave as boolean (why?) // // To ensure compatibility we return a bool if the bitstring is single-length. // Maybe we don't need to do this (why do we?) or maybe people used to some other, // but taking a conservative approach here. // // It means that IDataReader.GetValue() can't be used safely for bitstrings that // may be single-bit, but NpgsqlDataReader.GetBitString() can deal with the conversion // below by reversing it, so if GetBitString() is used, no harm is done. BitString bs = BitString.Parse(BackendData); return(bs.Length == 1 ? (object)bs[0] : bs); }
public void bsblocks() { var src = "0000010100001100101010001"; var bs = BitString.Parse(src); Claim.eq(bs.Length, 25); var b1 = bs.Partition(1); Claim.eq(src.Length, b1.Length); var b5 = bs.Partition(5); Claim.eq(5, b5.Length); var b3 = bs.Partition(3); Claim.eq(9, b3.Length); }
public void bs_to_u32() { var x0 = 0b_01011000_00001000_11111010_01100101u; var x1 = x0.ToBitString(); var x2 = x1.TakeValue <uint>(); Claim.eq(x0, x2); var x = 0b10100001100101010001u; var bsSrc = "0000010100001100101010001"; var bs1 = BitString.Parse(bsSrc); Claim.eq((int)bs1.Length, bsSrc.Length); var bs2 = BitString.FromScalar(x); var y = bs1.TakeValue <uint>(); Claim.eq(x, y); Claim.yea(bs1.Equals(bs2)); }