public static ulong SetSlice(this IBitString bits, int from, int to, ulong val) { ulong mask = (~0uL << to) & (~0uL >> (63 - from)); return // Clear bits ((bits.Value & ~mask) // Set bits | ((val << to) & mask)); }
public static bitN SliceN(this IBitString bits, int from, int to) { ulong val = bits.Slice(from, to); return(bitN.OfValue(val, to - from + 1)); }
/// NOTE v[m:l] -> m is MSB, L is LSB, LSB starts at 0 e.g. 0xF0[7:4]=0x0F; 0xF0[3:0]=0x00 public static ulong Slice(this IBitString bits, int from, int to) { return((bits.Value >> (bits.BitWidth - to)) & ~(~0uL << (to - from + 1))); }