hicosim.control.utils
Class BitUtils

java.lang.Object
  extended by hicosim.control.utils.BitUtils

public class BitUtils
extends java.lang.Object

Hilfsklasse, welche Methoden fuer Bitoperationen bereitstellt. Class which provides methods for bitmanipulation.

Author:
Calchera, Wager, Obermueller

Constructor Summary
BitUtils()
           
 
Method Summary
static long binary2Decimal(java.lang.String binaryString)
          convert a binaryString to a decimal number
static int checkBitsRange(int instr, int start, int end, int check)
           
static int clearBit(int n, int pos)
           
static java.lang.String convert(java.lang.Integer number, Numeratives numeratives, boolean grouped)
          This method converts an Integer-Object from the decimal numerative into other numeratives and returns the result as a String-Object.
static java.lang.String convert(java.lang.Long number, Numeratives numeratives, boolean grouped)
           
static int flipBit(int n, int pos)
           
static int fourBytesToOneInteger(int a, int b, int c, int d)
          this method converts four bytes to one integer.
static int hex2Decimal(java.lang.String hexWord)
          convert a hexadecimal string to a decimal number
static boolean isXPot(int pot, int N)
          This methos checks if the number N is a pot of param pot
static int octalToDecimal(java.lang.String octalNumberAsString)
          This method converts an octal number, which is passed as a String-Object "octalNumberAsString", into a decimal number and returns it as an Integer-Object.
static long pot(long x, long n)
           
static int setBit(int n, int pos)
           
static boolean testBit(int n, int pos)
           
 int twosComplement(int x)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BitUtils

public BitUtils()
Method Detail

setBit

public static int setBit(int n,
                         int pos)

clearBit

public static int clearBit(int n,
                           int pos)

flipBit

public static int flipBit(int n,
                          int pos)

testBit

public static boolean testBit(int n,
                              int pos)

checkBitsRange

public static int checkBitsRange(int instr,
                                 int start,
                                 int end,
                                 int check)
Parameters:
instr - int wert zum testen
start - start position
end - letzte position
check - art des bit zum testen 0,1
Returns:
-1==fehler,0=false,1=true beispiel: 00000000000000000000000000000001 byte==1 int int i=1; checkBitsRange(i,31,1,0) returns 1; checkBitsRange(i,31,0,0) returns 0; checkBitsRange(i,1,2,0) returns -1;

twosComplement

public int twosComplement(int x)

convert

public static java.lang.String convert(java.lang.Integer number,
                                       Numeratives numeratives,
                                       boolean grouped)
This method converts an Integer-Object from the decimal numerative into other numeratives and returns the result as a String-Object. The enumeration "Numeratives" must be extended in order to be able to extend this method.

Parameters:
- - Integer number
- - Numeratives numeratives
- - boolean grouped
Returns:
- String

convert

public static java.lang.String convert(java.lang.Long number,
                                       Numeratives numeratives,
                                       boolean grouped)

isXPot

public static boolean isXPot(int pot,
                             int N)
This methos checks if the number N is a pot of param pot

Parameters:
pot -
N -
Returns:
true if N is a pot of param pot and if not then false

hex2Decimal

public static int hex2Decimal(java.lang.String hexWord)
convert a hexadecimal string to a decimal number

Parameters:
hexWord - ==> for instance: ff -> returns 255
Returns:
int: decimal value of hexadecimal string

octalToDecimal

public static int octalToDecimal(java.lang.String octalNumberAsString)
This method converts an octal number, which is passed as a String-Object "octalNumberAsString", into a decimal number and returns it as an Integer-Object. The method works with inputs, that use the leading zero and inputs that don't use it. (E.g. octalToDecimal("18") will return 16).

Parameters:
String - octalNumberAsString
Returns:
int

binary2Decimal

public static long binary2Decimal(java.lang.String binaryString)
convert a binaryString to a decimal number

Parameters:
binaryString - ==> for instance: 00000000100000001000000010000001 --> return: 8421505 ==> 10000010000000000000000000000000 --> return: -2113929216
Returns:
int: decimal value of binaryString

pot

public static long pot(long x,
                       long n)

fourBytesToOneInteger

public static int fourBytesToOneInteger(int a,
                                        int b,
                                        int c,
                                        int d)
this method converts four bytes to one integer. (see method readInt() from java.io.DataInput)

Parameters:
a -
b -
c -
d -
Returns:
- the integer value of the given four bytes