Package mathvoyage.bitwise
Class Bitwise
java.lang.Object
mathvoyage.bitwise.Bitwise
The type Bitwise.
-
Method Summary
Modifier and TypeMethodDescriptionbooleanaddOK(int x, int y, boolean isUnsigned) returns true if the addition of x and y does not result in overflow, and false otherwise.intBitWiseAND(int a, int b) Return the bitwise And valueintBitWiseNOT(int a) Return the NOT valueintBitWiseOR(int a, int b) Return the OR valueintBitWiseXOR(int a, int b) Return the XOR valuebitwiseZeroFillRightShift(int binaryNumber, int shiftAmount) Return the zero fill right shift valueintgetByte(int x, int n, boolean isUnsigned) Returns the value of the n-th byte of the integer xstatic BitwiseReturns the singleton instance of this class.intleftShift(int num, int shiftBy, boolean isUnsigned) Return the LeftShift valueintlogicalShift(int x, int n, boolean isUnsigned) Returns an integer resulting from the logical right shiftintrightShift(int num, int shiftBy, boolean isUnsigned) Return the rightshift valueintrotateLeft(int x, int n, boolean isUnsigned) Returns an integer resulting from the left rotationintrotateRight(int x, int n, boolean isUnsigned) Returns an integer resulting from the right rotationintsetBit0(int n, int i) Returns an integer where the bit at position i in n is set to 0, and all other bits remain unchanged.intsetBit1(int n, int i) Returns an integer where the bit at position i in n is set to 1, and all other bits remain unchanged.inttoggleBit(int n, int i) returns an integer where the bit at position i in n is flipped
-
Method Details
-
getInstance
Returns the singleton instance of this class.- Returns:
- The singleton instance
-
BitWiseOR
public int BitWiseOR(int a, int b) Return the OR value- Parameters:
a- is the int value givenb- is the int value given- Returns:
- or value
-
BitWiseAND
public int BitWiseAND(int a, int b) Return the bitwise And value- Parameters:
a- is the given valueb- is the given value- Returns:
- AND value
-
BitWiseNOT
public int BitWiseNOT(int a) Return the NOT value- Parameters:
a- is the int value- Returns:
- the NOT value
-
BitWiseXOR
public int BitWiseXOR(int a, int b) Return the XOR value- Parameters:
a- is the int valueb- is the int value- Returns:
- the XOR value
-
rightShift
public int rightShift(int num, int shiftBy, boolean isUnsigned) Return the rightshift value- Parameters:
num- the int valueshiftBy- is the value of how much value need to be shiftedisUnsigned- is the boolean value- Returns:
- the rightshift value
-
leftShift
public int leftShift(int num, int shiftBy, boolean isUnsigned) Return the LeftShift value- Parameters:
num- the int valueshiftBy- is the value of how much value need to be shiftedisUnsigned- is the boolean value- Returns:
- the LeftShift value
-
bitwiseZeroFillRightShift
Return the zero fill right shift value- Parameters:
binaryNumber- the int valueshiftAmount- is the value of how much value need to be shifted- Returns:
- the zero fill right shift value`
-
getByte
public int getByte(int x, int n, boolean isUnsigned) Returns the value of the n-th byte of the integer x- Parameters:
x- The integer from which to extract the byte.n- The byte position to extractisUnsigned- Whether the number is unsigned- Returns:
- the value of the n-th byte of the integer x
-
setBit0
public int setBit0(int n, int i) Returns an integer where the bit at position i in n is set to 0, and all other bits remain unchanged.- Parameters:
n- The integer on which to operate.i- The bit position to set to 0.- Returns:
- an integer where the bit at position i in n is set to 0, and all other bits remain unchanged.
-
setBit1
public int setBit1(int n, int i) Returns an integer where the bit at position i in n is set to 1, and all other bits remain unchanged.- Parameters:
n- The integer on which to operate.i- The bit position to set to 1.- Returns:
- an integer where the bit at position i in n is set to 1, and all other bits remain unchanged.
-
toggleBit
public int toggleBit(int n, int i) returns an integer where the bit at position i in n is flipped- Parameters:
n- The integer on which to operate.i- The bit position to toggle.- Returns:
- an integer where the bit at position i in n is flipped
-
logicalShift
public int logicalShift(int x, int n, boolean isUnsigned) Returns an integer resulting from the logical right shift- Parameters:
x- The integer on which to perform the shift.n- The number of positions to shift to the right.isUnsigned- Whether the number is unsigned.- Returns:
- an integer resulting from the logical right shift
-
rotateRight
public int rotateRight(int x, int n, boolean isUnsigned) Returns an integer resulting from the right rotation- Parameters:
x- The integer on which to perform the rotation.n- The number of positions to rotate to the right.isUnsigned- Whether the number is unsigned.- Returns:
- an integer resulting from the right rotation
-
rotateLeft
public int rotateLeft(int x, int n, boolean isUnsigned) Returns an integer resulting from the left rotation- Parameters:
x- The integer on which to perform the rotationn- The number of positions to rotate to the leftisUnsigned- Whether the number is unsigned- Returns:
- an integer resulting from the left rotation
-
addOK
public boolean addOK(int x, int y, boolean isUnsigned) returns true if the addition of x and y does not result in overflow, and false otherwise.- Parameters:
x- The first integer operand.y- The second integer operand.isUnsigned- Whether the numbers are unsigned.- Returns:
- true if the addition of x and y does not result in overflow, and false otherwise.
-