Exemplo n.º 1
0
        /// <summary>
        /// Returns true if all of bits in range are set.
        /// </summary>
        /// <param name="pos">Position in bitfield (must be 0-63).</param>
        /// <param name="numBits">Number of bits to set (must be 1-64).</param>
        /// <returns>Returns true if all bits are set.</returns>
        public bool TestAll(int pos, int numBits = 1)
        {
            CheckArgs(pos, numBits);
            var mask = 0xfffffffffffffffful >> (64 - numBits);

            return(mask == Bitwise.ExtractBits(Value, pos, mask));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Returns all bits in range as uint.
        /// </summary>
        /// <param name="pos">Position in bitfield (must be 0-63).</param>
        /// <param name="numBits">Number of bits to set (must be 1-64).</param>
        /// <returns>Returns requested range of bits.</returns>
        public ulong GetBits(int pos, int numBits = 1)
        {
            CheckArgs(pos, numBits);
            var mask = 0xfffffffffffffffful >> (64 - numBits);

            return(Bitwise.ExtractBits(Value, pos, mask));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Set bits to desired boolean value.
        /// </summary>
        /// <param name="pos">Position in bitfield (must be 0-63).</param>
        /// <param name="value">Value of bits to set.</param>
        /// <param name="numBits">Number of bits to set (must be 1-64).</param>
        public void SetBits(int pos, bool value, int numBits = 1)
        {
            CheckArgs(pos, numBits);
            var mask = 0xfffffffffffffffful >> (64 - numBits);

            Value = Bitwise.SetBits(Value, pos, mask, value);
        }
Exemplo n.º 4
0
 /// <summary>
 /// Set single bit to desired boolean value.
 /// </summary>
 /// <param name="pos">Position in bitfield (must be 0-31).</param>
 /// <param name="value">Value of bits to set.</param>
 public void SetBits(int pos, bool value)
 {
     CheckArgs(pos, 1);
     Value = Bitwise.SetBits(Value, pos, 1, value);
 }
Exemplo n.º 5
0
 /// <summary>
 /// Calculate number of trailing zeros.
 /// </summary>
 /// <returns>Number of trailing zeros</returns>
 public int CountTrailingZeros()
 {
     return(Bitwise.CountTrailingZeros(Value));
 }
Exemplo n.º 6
0
 /// <summary>
 /// Calculate number of leading zeros.
 /// </summary>
 /// <returns>Number of leading zeros</returns>
 public int CountLeadingZeros()
 {
     return(Bitwise.CountLeadingZeros(Value));
 }
Exemplo n.º 7
0
 /// <summary>
 /// Calculate number of set bits.
 /// </summary>
 /// <returns>Number of set bits.</returns>
 public int CountBits()
 {
     return(Bitwise.CountBits(Value));
 }