类 Bits


  • public class Bits
    extends java.lang.Object
    Util for bit operation. The methods of this class do not do any range check, caller should take care this.
    • 构造器概要

      构造器 
      构造器 说明
      Bits()  
    • 方法概要

      所有方法 静态方法 具体方法 
      修饰符和类型 方法 说明
      static int clear​(int v, int idx)
      Clear the bit in value
      static int clear​(int v, int from, int to)
      Clear bits of value, in range [from, to).The indexes are starts with 0, from low to high.
      static long clear​(long v, int idx)
      Clear the bit in value
      static long clear​(long v, int from, int to)
      Clear bits of value, in range [from, to).
      static int flip​(int v, int idx)
      Set the bit in value to the complement of current.
      static int flip​(int v, int from, int to)
      Set bits of value, in range [from, to), to the complement of current values.
      static long flip​(long v, int idx)
      Set the bit in value to the complement of current.
      static long flip​(long v, int from, int to)
      Set bits of value, in range [from, to), to the complement of current values.
      static int set​(int v, int idx)
      Set the bit in value
      static int set​(int v, int from, int to)
      Set bits of value, in range [from, to).
      static long set​(long v, int idx)
      Set the bit in value
      static long set​(long v, int from, int to)
      Set bits of value, in range [from, to).
      static int take​(int v, int from, int to)
      Take bits of value, in range [from, to), to be a new value.
      static long take​(long v, int from, int to)
      Take bits of value, in range [from, to), to be a new value.
      static int takeDown​(int v, int from, int to)
      Take bits of value, in range [from, to), and then shift to lowest bits, to be a new value.
      static long takeDown​(long v, int from, int to)
      Take bits of value, in range [from, to), and then shift to lowest bits, to be a new value.
      static boolean test​(int v, int idx)
      If the bit in value is set.
      static boolean test​(long v, int idx)
      If the bit in value is set.
      • 从类继承的方法 java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 构造器详细资料

      • Bits

        public Bits()
    • 方法详细资料

      • test

        public static boolean test​(int v,
                                   int idx)
        If the bit in value is set.
        参数:
        v - the value
        idx - bit index, starts with 0, from low to high
        返回:
        if bit is set
      • set

        public static int set​(int v,
                              int idx)
        Set the bit in value
        参数:
        v - the value
        idx - bit index, starts with 0, from low to high
        返回:
        new value with the bit set
      • clear

        public static int clear​(int v,
                                int idx)
        Clear the bit in value
        参数:
        v - the value
        idx - bit index, starts with 0, from low to high
        返回:
        new value with the bit cleared
      • flip

        public static int flip​(int v,
                               int idx)
        Set the bit in value to the complement of current.
        参数:
        v - the value
        idx - bit index, starts with 0, from low to high
        返回:
        new value with the bit flipped
      • set

        public static int set​(int v,
                              int from,
                              int to)
        Set bits of value, in range [from, to). The indexes are starts with 0, from low to high.
        参数:
        v - the original value
        from - the from bit index, include
        to - the to bit index, exclude
        返回:
        the value with bits set
      • clear

        public static int clear​(int v,
                                int from,
                                int to)
        Clear bits of value, in range [from, to).The indexes are starts with 0, from low to high.
        参数:
        v - the original value
        from - the from bit index, include
        to - the to bit index, exclude
        返回:
        the value with bits cleared
      • flip

        public static int flip​(int v,
                               int from,
                               int to)
        Set bits of value, in range [from, to), to the complement of current values. The indexes are starts with 0, from low to high.
        参数:
        v - the original value
        from - the from bit index, include
        to - the to bit index, exclude
        返回:
        the value with bits flipped
      • take

        public static int take​(int v,
                               int from,
                               int to)
        Take bits of value, in range [from, to), to be a new value. The other bits of new value is zero. The indexes are starts with 0, from low to high.
        参数:
        v - the original value
        from - the from bit index, include
        to - the to bit index, exclude
        返回:
        the new value
      • takeDown

        public static int takeDown​(int v,
                                   int from,
                                   int to)
        Take bits of value, in range [from, to), and then shift to lowest bits, to be a new value. The other bits of new value is zero. The indexes are starts with 0, from low to high.
        参数:
        v - the original value
        from - the from bit index, include
        to - the to bit index, exclude
        返回:
        the new value
      • test

        public static boolean test​(long v,
                                   int idx)
        If the bit in value is set.
        参数:
        v - the value
        idx - bit index, starts with 0, from low to high
        返回:
        if bit is set
      • set

        public static long set​(long v,
                               int idx)
        Set the bit in value
        参数:
        v - the value
        idx - bit index, starts with 0, from low to high
        返回:
        new value with the bit set
      • clear

        public static long clear​(long v,
                                 int idx)
        Clear the bit in value
        参数:
        v - the value
        idx - bit index, starts with 0, from low to high
        返回:
        new value with the bit cleared
      • flip

        public static long flip​(long v,
                                int idx)
        Set the bit in value to the complement of current.
        参数:
        v - the value
        idx - bit index, starts with 0, from low to high
        返回:
        new value with the bit flipped
      • set

        public static long set​(long v,
                               int from,
                               int to)
        Set bits of value, in range [from, to). The indexes are starts with 0, from low to high.
        参数:
        v - the original value
        from - the from bit index, include
        to - the to bit index, exclude
        返回:
        the value with bits set
      • clear

        public static long clear​(long v,
                                 int from,
                                 int to)
        Clear bits of value, in range [from, to). The indexes are starts with 0, from low to high.
        参数:
        v - the original value
        from - the from bit index, include
        to - the to bit index, exclude
        返回:
        the value with bits cleared
      • flip

        public static long flip​(long v,
                                int from,
                                int to)
        Set bits of value, in range [from, to), to the complement of current values. The indexes are starts with 0, from low to high.
        参数:
        v - the original value
        from - the from bit index, include
        to - the to bit index, exclude
        返回:
        the value with bits flipped
      • take

        public static long take​(long v,
                                int from,
                                int to)
        Take bits of value, in range [from, to), to be a new value. The other bits of new value is zero. The indexes are starts with 0, from low to high.
        参数:
        v - the original value
        from - the from bit index, include
        to - the to bit index, exclude
        返回:
        the new value
      • takeDown

        public static long takeDown​(long v,
                                    int from,
                                    int to)
        Take bits of value, in range [from, to), and then shift to lowest bits, to be a new value. The other bits of new value is zero. The indexes are starts with 0, from low to high.
        参数:
        v - the original value
        from - the from bit index, include
        to - the to bit index, exclude
        返回:
        the new value