public final class BitOperations extends Object
Modifier and Type | Method and Description |
---|---|
static long[] |
getAllSubsets(long n)
Returns an array of all the bitwise subsets of the parameter number.
|
static long |
getLSBit(long n)
Returns the least significant (rightmost) bit in a long.
|
static long |
getMSBit(long n)
Returns the most significant (leftmost) bit in a long.
|
static byte |
hammingWeight(long n)
Returns the number of set bits in a long.
|
static byte |
indexOfBit(long n)
Returns the index of the single bit set in the input variable.
|
static byte |
indexOfLSBit(long n)
Returns the index of the least significant (rightmost) bit in a long.
|
static byte |
indexOfMSBit(long n)
Returns the index of the most significant (leftmost) bit in a long.
|
static long |
resetLSBit(long n)
Returns a long with the least significant (rightmost) bit in the input parameter reset.
|
static long |
resetMSBit(long n)
Returns a long with the most significant (leftmost) bit in the input parameter reset.
|
static long |
reverse(long n)
Returns a long with the bits of the input parameter reversed.
|
static long |
reverseBytes(long n)
Returns a long with the bytes of the input parameter reversed/flipped.
|
static byte[] |
serialize(long n)
Returns an array of the indexes of all set bits in the input parameter.
|
static String |
toBinaryLiteral(long n)
Returns the binary literal of the input long as a string.
|
static String |
toBinaryString(long n)
Returns a string representation of a long in binary form with all the 64 bits displayed whether set or not.
|
static long |
toBit(int i)
Returns a long integer with only the bit at the specified index set.
|
static String |
toHexLiteral(long n)
Returns the hexadecimal literal of the input long as a string.
|
public static long toBit(int i)
i
- The index of the bit.public static byte indexOfBit(long n)
n
- The number with a single set bit.public static long getMSBit(long n)
n
- The number.public static long resetMSBit(long n)
n
- The number.public static byte indexOfMSBit(long n)
n
- The number.public static long getLSBit(long n)
n
- The number.public static long resetLSBit(long n)
n
- The number.public static byte indexOfLSBit(long n)
n
- The number.public static byte hammingWeight(long n)
n
- The number.public static long reverse(long n)
n
- The number.public static long reverseBytes(long n)
n
- The number.public static byte[] serialize(long n)
n
- The number.public static long[] getAllSubsets(long n)
n
- The number.public static String toBinaryString(long n)
n
- The number.public static String toBinaryLiteral(long n)
n
- The number.public static String toHexLiteral(long n)
n
- The number.Copyright © 2020. All rights reserved.