Package mathvoyage
Class vmath.bitwise
java.lang.Object
mathvoyage.vmath.bitwise
- Enclosing class:
vmath
Contains functions to calculate bitwise operations.
- Author:
- Takia Farhin
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanreturns true if the addition of a and b does not result in overflow, and false otherwise.static intand(int a, int b) Return the bitwise And valuestatic intReturns the n'th byte of the integer a.static intleftRotate(int x, int n, signType st) Returns an integer resulting from the left rotationstatic intReturn the leftshift valuestatic intlogicalShift(int x, int n, signType st) Returns an integer resulting from the logical right shiftstatic intnot(int a) Return the bitwise NOT valuestatic intor(int a, int b) Return the bitwise OR valuestatic intrightRotate(int x, int n, signType st) Returns an integer resulting from the right rotationstatic intrightShift(int a, int b, signType st) Return the rightshift valuestatic intsetBit0(int a, int i) Returns an integer where the bit at position i in a is set to 0, and all other bits remain unchanged.static intsetBit1(int a, int i) Returns an integer where the bit at position i in a is set to 1, and all other bits remain unchanged.static inttoggleBit(int a, int i) Returns an integer where the bit at position i in a is flippedstatic intxor(int a, int b) Return the bitwise XOR valuestatic StringzeroFillRightShift(int a, int b) Returns the binary representation of a number.
-
Constructor Details
-
bitwise
public bitwise()
-
-
Method Details
-
and
public static int and(int a, int b) Return the bitwise And value- Parameters:
a- is the given valueb- is the given value- Returns:
- AND value
-
or
public static int or(int a, int b) Return the bitwise OR value- Parameters:
a- is the given valueb- is the given value- Returns:
- OR value
-
xor
public static int xor(int a, int b) Return the bitwise XOR value- Parameters:
a- is the given valueb- is the given value- Returns:
- XOR value
-
not
public static int not(int a) Return the bitwise NOT value- Parameters:
a- is the given value- Returns:
- NOT value
-
leftShift
Return the leftshift value- Parameters:
a- the int valueb- is the value of how much value need to be shiftedst- is the sign type- Returns:
- the rightshift value
-
rightShift
Return the rightshift value- Parameters:
a- the int valueb- is the value of how much value need to be shiftedst- is the sign type- Returns:
- the rightshift value
-
zeroFillRightShift
Returns the binary representation of a number.- Parameters:
a- The number to be convertedb- The number of bits to shift- Returns:
- The binary representation of the number
-
getByte
Returns the n'th byte of the integer a.- Parameters:
a- The integern- The byte numberst- The sign type- Returns:
- The n'th byte of the integer a
-
setBit0
public static int setBit0(int a, int i) Returns an integer where the bit at position i in a is set to 0, and all other bits remain unchanged.- Parameters:
a- The integeri- The position- Returns:
- The integer where the bit at position i in a is set to 0
-
setBit1
public static int setBit1(int a, int i) Returns an integer where the bit at position i in a is set to 1, and all other bits remain unchanged.- Parameters:
a- The integeri- The position- Returns:
- The integer where the bit at position i in a is set to 1
-
toggleBit
public static int toggleBit(int a, int i) Returns an integer where the bit at position i in a is flipped- Parameters:
a- 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
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.st- The sign type- Returns:
- an integer resulting from the logical right shift
-
rightRotate
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.st- The sign type- Returns:
- an integer resulting from the right rotation
-
leftRotate
Returns an integer resulting from the left rotation- Parameters:
x- The integer on which to perform the rotation.n- The number of positions to rotate to the left.st- The sign type- Returns:
- an integer resulting from the left rotation
-
addOK
returns true if the addition of a and b does not result in overflow, and false otherwise.- Parameters:
a- The first integer operand.b- The second integer operand.st- The sign type- Returns:
- true if the addition of x and y does not result in overflow, and false otherwise.
-