类 Bits
- java.lang.Object
-
- net.dongliu.commons.io.Bits
-
public class Bits extends java.lang.ObjectUtil for bit operation. The methods of this class do not do any range check, caller should take care this.
-
-
构造器概要
构造器 构造器 说明 Bits()
-
方法概要
所有方法 静态方法 具体方法 修饰符和类型 方法 说明 static intclear(int v, int idx)Clear the bit in valuestatic intclear(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 longclear(long v, int idx)Clear the bit in valuestatic longclear(long v, int from, int to)Clear bits of value, in range [from, to).static intflip(int v, int idx)Set the bit in value to the complement of current.static intflip(int v, int from, int to)Set bits of value, in range [from, to), to the complement of current values.static longflip(long v, int idx)Set the bit in value to the complement of current.static longflip(long v, int from, int to)Set bits of value, in range [from, to), to the complement of current values.static intset(int v, int idx)Set the bit in valuestatic intset(int v, int from, int to)Set bits of value, in range [from, to).static longset(long v, int idx)Set the bit in valuestatic longset(long v, int from, int to)Set bits of value, in range [from, to).static inttake(int v, int from, int to)Take bits of value, in range [from, to), to be a new value.static longtake(long v, int from, int to)Take bits of value, in range [from, to), to be a new value.static inttakeDown(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 longtakeDown(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 booleantest(int v, int idx)If the bit in value is set.static booleantest(long v, int idx)If the bit in value is set.
-
-
-
方法详细资料
-
test
public static boolean test(int v, int idx)If the bit in value is set.- 参数:
v- the valueidx- 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 valueidx- 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 valueidx- 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 valueidx- 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 valuefrom- the from bit index, includeto- 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 valuefrom- the from bit index, includeto- 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 valuefrom- the from bit index, includeto- 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 valuefrom- the from bit index, includeto- 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 valuefrom- the from bit index, includeto- 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 valueidx- 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 valueidx- 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 valueidx- 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 valueidx- 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 valuefrom- the from bit index, includeto- 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 valuefrom- the from bit index, includeto- 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 valuefrom- the from bit index, includeto- 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 valuefrom- the from bit index, includeto- 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 valuefrom- the from bit index, includeto- the to bit index, exclude- 返回:
- the new value
-
-