Package mathvoyage

Class vmath.bitwise

java.lang.Object
mathvoyage.vmath.bitwise
Enclosing class:
vmath

public static class vmath.bitwise extends Object
Contains functions to calculate bitwise operations.
Author:
Takia Farhin
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    addOK(int a, int b, signType st)
    returns true if the addition of a and b does not result in overflow, and false otherwise.
    static int
    and(int a, int b)
    Return the bitwise And value
    static int
    getByte(int a, int n, signType st)
    Returns the n'th byte of the integer a.
    static int
    leftRotate(int x, int n, signType st)
    Returns an integer resulting from the left rotation
    static int
    leftShift(int a, int b, signType st)
    Return the leftshift value
    static int
    logicalShift(int x, int n, signType st)
    Returns an integer resulting from the logical right shift
    static int
    not(int a)
    Return the bitwise NOT value
    static int
    or(int a, int b)
    Return the bitwise OR value
    static int
    rightRotate(int x, int n, signType st)
    Returns an integer resulting from the right rotation
    static int
    rightShift(int a, int b, signType st)
    Return the rightshift value
    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.
    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.
    static int
    toggleBit(int a, int i)
    Returns an integer where the bit at position i in a is flipped
    static int
    xor(int a, int b)
    Return the bitwise XOR value
    static String
    zeroFillRightShift(int a, int b)
    Returns the binary representation of a number.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 value
      b - 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 value
      b - 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 value
      b - 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

      public static int leftShift(int a, int b, signType st)
      Return the leftshift value
      Parameters:
      a - the int value
      b - is the value of how much value need to be shifted
      st - is the sign type
      Returns:
      the rightshift value
    • rightShift

      public static int rightShift(int a, int b, signType st)
      Return the rightshift value
      Parameters:
      a - the int value
      b - is the value of how much value need to be shifted
      st - is the sign type
      Returns:
      the rightshift value
    • zeroFillRightShift

      public static String zeroFillRightShift(int a, int b)
      Returns the binary representation of a number.
      Parameters:
      a - The number to be converted
      b - The number of bits to shift
      Returns:
      The binary representation of the number
    • getByte

      public static int getByte(int a, int n, signType st)
      Returns the n'th byte of the integer a.
      Parameters:
      a - The integer
      n - The byte number
      st - 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 integer
      i - 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 integer
      i - 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

      public static int logicalShift(int x, int n, signType st)
      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

      public static int rightRotate(int x, int n, signType st)
      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

      public static int leftRotate(int x, int n, signType st)
      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

      public static boolean addOK(int a, int b, signType st)
      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.