|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectgenopt.algorithm.util.math.Binary
public class Binary
Mathematical functions for binary numbers.
This project was carried out at:
and supported byGenOpt Copyright (c) 1998-2011, The Regents of the University of California, through Lawrence Berkeley National Laboratory (subject to receipt of any required approvals from the U.S. Dept. of Energy). All rights reserved.
| Field Summary | |
|---|---|
private static int |
BIT_SIZE
The number of bits used to present binary numbers |
| Constructor Summary | |
|---|---|
private |
Binary()
Empty constructor. |
| Method Summary | |
|---|---|
private static long |
binaryToLong(char[] charArray)
Converts a binary char array to
the long number it presents. |
private static long |
binaryToLong(int[] intArray)
Converts a binary int array to
the long number it presents. |
private static java.lang.String |
binaryToString(int[] intArr,
int length)
Returns a String representation of the argument
that contains 0 or 1. |
static long |
getGrayCode(long n)
Gets the Gray code. |
static long |
getInverseGrayCode(int[] gray)
Gets the inverse of the Gray code of a binary int array. |
static long |
getInverseGrayCode(long gray)
Gets the inverse of the Gray code. |
static long |
getL2Norm(int[] i,
int[] j)
Gets the L2 norm. |
static int |
getStringLength(long n)
Gets the length of the binary string required to represent the argument. |
static long |
ieor(long i,
long j)
Computes the value of a bitwise exclusive or between the arguments. |
static char[] |
increaseLength(char[] binStr,
int length)
Increases the length of a char array by
setting additional elements with 0. |
static long |
ishft(long i,
int shift)
Computes the value obtained by shifting the bits of i
by shift positions. |
static void |
main(java.lang.String[] args)
|
static char[] |
toBinaryChar(long i)
Returns a char[] representation of the long
argument as an unsigned integer in base 2. |
private static int[] |
toBinaryInt(char[] c)
Converts a char array with binary values to
a binary int array. |
static int[] |
toBinaryInt(long i)
Returns an int[] representation of the long
argument as an unsigned integer in base 2. |
static int[] |
toBinaryInt(long i,
int length)
Returns an int[] representation of the long
argument as an unsigned integer in base 2. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
private static final int BIT_SIZE
| Constructor Detail |
|---|
private Binary()
static methods and fields.
| Method Detail |
|---|
public static final long getL2Norm(int[] i,
int[] j)
i - an integer arrayj - an integer array
java.lang.IllegalArgumentException - if the arguments have different lengthpublic static char[] toBinaryChar(long i)
char[] representation of the long
argument as an unsigned integer in base 2.
i - a long to be converted to a char[].
char[] representation of the
unsigned long value represented by the argument
in binary (base 2).public static int[] toBinaryInt(long i)
int[] representation of the long
argument as an unsigned integer in base 2.
i - a long to be converted to an int[].
int[] representation of the
unsigned long value represented by the argument
in binary (base 2).
public static int[] toBinaryInt(long i,
int length)
int[] representation of the long
argument as an unsigned integer in base 2.
i - a long to be converted to an int[].length - number of elements of the returned array
int[] representation of the
unsigned long value represented by the argument
in binary (base 2).
java.lang.IllegalArgumentException - if length is
not long enough to represent the argument as a binary integer array
public static int getStringLength(long n)
throws java.lang.IllegalArgumentException
n - argument whose required length will be computed.
java.lang.IllegalArgumentException - if n < 0
private static final java.lang.String binaryToString(int[] intArr,
int length)
throws java.lang.IllegalArgumentException
String representation of the argument
that contains 0 or 1.
intArr - an int[] array containing 0 or 1length - the length of the string array that will be returned
String representation of the argument
java.lang.IllegalArgumentException - if the argument contains non-binary
numbers
public static long getGrayCode(long n)
throws java.lang.IllegalArgumentException
n - non-negative argument whose length will be computed
java.lang.IllegalArgumentException - if n < 0private static int[] toBinaryInt(char[] c)
char array with binary values to
a binary int array.
c - a char array with 0 and 1
elements
c converted to an int array
java.lang.IllegalArgumentException - if c is not a binary arrayprivate static long binaryToLong(int[] intArray)
int array to
the long number it presents.
intArray - a binary int array
private static long binaryToLong(char[] charArray)
throws java.lang.IllegalArgumentException
char array to
the long number it presents.
charArray - a binary int array
java.lang.IllegalArgumentException - if c is not a binary arraypublic static long getInverseGrayCode(int[] gray)
int array.
gray is first encoded in a long value,
and then the inverse Gray coding of the long is
computed and returned.
gray - an int[] argument with binary numbers
gray, using inverse
Gray codingpublic static long getInverseGrayCode(long gray)
gray - a number in Gray code
gray, using inverse
Gray coding
public static final char[] increaseLength(char[] binStr,
int length)
throws java.lang.IllegalArgumentException
char array by
setting additional elements with 0.
If n=binStr.length < length , then
the return argument has 0 at the
elements 0 to lenth-n.
binStr - the binary string string to be extendedlength - the length of the returned binary string
binStr with increased length
java.lang.IllegalArgumentException - if binStr.length > length
public static final long ieor(long i,
long j)
i - first argumentj - second argument
public static final long ishft(long i,
int shift)
i
by shift positions.
If shift is positive, the shift is to the left,
otherwise to the right.
Bits shifted off the left or right are lost and zero bits are
shifted in from the opposite end.
i - value whose bits will be shiftedshift - number of positions that the bits will be shifted
i after shifting the bitspublic static void main(java.lang.String[] args)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||