SciLib.Math
Class bitStream

java.lang.Object
  extended by SciLib.Math.bitStream

public class bitStream
extends java.lang.Object

This class contains some methods to handle a string of bits.


Constructor Summary
bitStream()
          Allocates a new bitStream containing no data.
bitStream(booleanVector bits)
          Allocates a new bitStream containing a initialized booleanVector bits.
bitStream(byte b)
          Allocates a new bitString containing a bits representation of a byte b.
bitStream(byte[] b)
          Allocates a new bitString containing a bits representation of a byte array b.
bitStream(char c, boolean t)
          Allocates a new bitString containing a bits representation of a character c.
bitStream(int[] b)
          Allocates a new bitStream containing a initialized pulse array.
bitStream(int n, boolean t)
          Allocates a new bitStream containing a bits representation of an integer n.
bitStream(java.lang.String b)
          Allocates a new bitStream containing a initialized bit character String.
 
Method Summary
 void add(boolean b)
          Add one bit 'b' to this bitStream
 void add(char b)
          Add one bit 'b' to this bitStream
 void add(int b)
          Add one bit b to this bitStream
 bitStream and(bitStream b)
          Apply and method between this bitStream and a bitStream b
 bitStream and(bitStream b, int ind)
          Apply and method between this bitStream and a bitStream b from the index i
static boolean and(boolean i, boolean j)
          and operation
static int and(int i, int j)
          and operation
 void append(bitStream b)
          Append the bitStream with a bitStream b
 char bitAt(int i)
          return the character of the bit i int the bitStream
static char bitChar(boolean b)
          convert a digital pulse to bit character
static int bitrev(int n, int q)
          return a number that is made by bitreversal of the integer n using q-bits representation by q bits.
static int bits2num(int q)
          return the byggest integer number that can be repersented by q bits
static boolean booleanPulse(char b)
          convert a bit character to a digital pulse
static boolean booleanPulse(int b)
          convert an bit integer to a digital pulse
 boolean checkBit(int i, int j, boolean b)
          Check a bit value in a sequence of bits from index i to index j
static bitStream copy(bitStream bits)
          Make a copy of a given bitStream
 void cutLeft(int n)
          cut n bits of the bitStream from the left.
 void cutRight(int n)
          cut n bits of the bitStream from the right.
 boolean elementAt(int i)
          Return the bit i
 booleanVector getBits()
          get the booleanVector of the bitStream
static bitStream getBits(byte b, int i, int j)
          get n bits in a byte from index the i to the index j
 java.lang.String getTitle()
          get the title of the bitStream
 void leftShift(int n)
          Left-Shift n bits
 bitStream not()
          Apply or method between this bitStream and a bitStream b
static int num2bits(int n)
          compute the number of bits needed to represent an integer n.
 bitStream or(bitStream b)
          Apply or method between this bitStream and a bitStream b
 bitStream or(bitStream b, int ind)
          Apply or method between this bitStream and a bitStream b from the index i
static boolean or(boolean i, boolean j)
          or operation
static int or(int i, int j)
          or operation
 void print()
          write out the bitStream with System.out
static int pulse(boolean b)
          convert a digital pulse to an bit integer
 void rightShift(int n)
          Right-Shift n bits
 void setBits(booleanVector bits)
          Make a bitString object with an initialized string bits.
 void setBits(byte b)
          Make a bitStream representation of a byte b.
 void setBits(byte[] b)
          Make a bitStream representation of a byte array b.
 void setBits(char c)
          Make a bitStream representation of a character c.
 void setBits(int n)
          Make a bitStream representation of an integer n.
 void setElementAt(boolean b, int i)
          Set new value of the bitStream at index i
 void setTitle(java.lang.String name)
          set Title to the bitStream
 int[] signal()
          Make an array of integers that represents the bitStream
 int size()
          return the size of the bitStream
 bitStream subBitStream(int from)
          make a subBitStream from the index "from" to the end of this bitStream.
 bitStream subBitStream(int from, int to)
          Make a subBitStream from the index "from" to the index "to".
 java.lang.String toString()
          Make a String from the bitStream
 void trim()
          cut off the zeros leading of the bitString
 long value()
          return the long value represented by bitStream.
 bitStream xor(bitStream b)
          Apply xor method between this bitStream and a bitStream b
 bitStream xor(bitStream b, int ind)
          Apply xor method between this bitStream and a bitStream b from the index i
static boolean xor(boolean i, boolean j)
          xor operation
static int xor(int i, int j)
          xor operation
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

bitStream

public bitStream()
Allocates a new bitStream containing no data.


bitStream

public bitStream(int n,
                 boolean t)
Allocates a new bitStream containing a bits representation of an integer n.

Parameters:
n - An integer
t - A boolean, true for trim, i.e. cut off the zeros leading of the bitString

bitStream

public bitStream(char c,
                 boolean t)
Allocates a new bitString containing a bits representation of a character c.

Parameters:
c - A character
t - A boolean, true for trim, i.e. cut off the zeros leading of the bitString

bitStream

public bitStream(byte b)
Allocates a new bitString containing a bits representation of a byte b.

Parameters:
b - A byte

bitStream

public bitStream(byte[] b)
Allocates a new bitString containing a bits representation of a byte array b.

Parameters:
b - A byte array

bitStream

public bitStream(booleanVector bits)
Allocates a new bitStream containing a initialized booleanVector bits.

Parameters:
bits - A booleanVector

bitStream

public bitStream(int[] b)
Allocates a new bitStream containing a initialized pulse array.

Parameters:
b - An integer array of 0s and 1s

bitStream

public bitStream(java.lang.String b)
Allocates a new bitStream containing a initialized bit character String.

Parameters:
b - A String of 0s and 1s
Method Detail

trim

public void trim()
cut off the zeros leading of the bitString


setBits

public void setBits(int n)
Make a bitStream representation of an integer n.

Parameters:
n - An integer

setBits

public void setBits(char c)
Make a bitStream representation of a character c.

Parameters:
c - The character

setBits

public void setBits(byte b)
Make a bitStream representation of a byte b.

Parameters:
b - a byte

setBits

public void setBits(byte[] b)
Make a bitStream representation of a byte array b.

Parameters:
b - a byte array

setBits

public void setBits(booleanVector bits)
Make a bitString object with an initialized string bits.

Parameters:
bits - A string

copy

public static bitStream copy(bitStream bits)
Make a copy of a given bitStream

Parameters:
bits - A bitStream
Returns:
A bitStream

print

public void print()
write out the bitStream with System.out


size

public int size()
return the size of the bitStream

Returns:
An integer

setTitle

public void setTitle(java.lang.String name)
set Title to the bitStream

Parameters:
name - A String

getTitle

public java.lang.String getTitle()
get the title of the bitStream

Returns:
A String

getBits

public booleanVector getBits()
get the booleanVector of the bitStream

Returns:
A booleanVector

bitAt

public char bitAt(int i)
return the character of the bit i int the bitStream

Returns:
A character, '1' for on, '0' for off

append

public void append(bitStream b)
Append the bitStream with a bitStream b

Parameters:
b - A bitStream

add

public void add(boolean b)
Add one bit 'b' to this bitStream

Parameters:
b - A boolean

add

public void add(char b)
Add one bit 'b' to this bitStream

Parameters:
b - A character, '1' or '0'

add

public void add(int b)
Add one bit b to this bitStream

Parameters:
b - An integer, 1 or 0

subBitStream

public bitStream subBitStream(int from,
                              int to)
Make a subBitStream from the index "from" to the index "to".

Parameters:
from - start index
to - end index
Returns:
A bitStream

subBitStream

public bitStream subBitStream(int from)
make a subBitStream from the index "from" to the end of this bitStream.

Parameters:
from - start index
Returns:
A vector

cutLeft

public void cutLeft(int n)
cut n bits of the bitStream from the left.

Parameters:
n - The number of bits

cutRight

public void cutRight(int n)
cut n bits of the bitStream from the right.

Parameters:
n - The number of bits

bits2num

public static final int bits2num(int q)
return the byggest integer number that can be repersented by q bits

Parameters:
q - The number of bits
Returns:
An integer

num2bits

public static final int num2bits(int n)
compute the number of bits needed to represent an integer n.

Parameters:
n - An integer number
Returns:
The number of bits

bitrev

public static final int bitrev(int n,
                               int q)
return a number that is made by bitreversal of the integer n using q-bits representation by q bits.

Parameters:
n - An integer number
q - The number of bits
Returns:
The number that is the bitreversal of n

elementAt

public boolean elementAt(int i)
Return the bit i

Parameters:
i - Index value
Returns:
A boolean

setElementAt

public void setElementAt(boolean b,
                         int i)
Set new value of the bitStream at index i

Parameters:
i - Index value
b - bit value

bitChar

public static char bitChar(boolean b)
convert a digital pulse to bit character

Parameters:
b - a pulse, on or off
Returns:
A character

pulse

public static int pulse(boolean b)
convert a digital pulse to an bit integer

Parameters:
b - a pulse, on or off
Returns:
An integer pulse

booleanPulse

public static boolean booleanPulse(int b)
convert an bit integer to a digital pulse

Parameters:
b - An integer, 0 or 1
Returns:
An boolean pulse

booleanPulse

public static boolean booleanPulse(char b)
convert a bit character to a digital pulse

Parameters:
b - A character, '0' or '1'
Returns:
An boolean pulse

signal

public int[] signal()
Make an array of integers that represents the bitStream

Returns:
An integer array of 1s and 0s

leftShift

public void leftShift(int n)
Left-Shift n bits

Parameters:
n - An integer

rightShift

public void rightShift(int n)
Right-Shift n bits

Parameters:
n - An integer

checkBit

public boolean checkBit(int i,
                        int j,
                        boolean b)
Check a bit value in a sequence of bits from index i to index j

Parameters:
i - from index
j - to in index
b - a pulse
Returns:
true or false

xor

public static boolean xor(boolean i,
                          boolean j)
xor operation

Parameters:
i - a pulse
j - a pulse
Returns:
i ^ j

xor

public static int xor(int i,
                      int j)
xor operation

Parameters:
i - a bit value
j - a bit value
Returns:
i ^ j

and

public static boolean and(boolean i,
                          boolean j)
and operation

Parameters:
i - pulse
j - pulse
Returns:
i & j

and

public static int and(int i,
                      int j)
and operation

Parameters:
i - a bit value
j - a bit value
Returns:
i & j

or

public static boolean or(boolean i,
                         boolean j)
or operation

Parameters:
i - a pulse
j - a pulse
Returns:
i & j

or

public static int or(int i,
                     int j)
or operation

Parameters:
i - a bit value
j - a bit value
Returns:
i & j

value

public long value()
return the long value represented by bitStream.

Returns:
A long value

getBits

public static bitStream getBits(byte b,
                                int i,
                                int j)
get n bits in a byte from index the i to the index j

Parameters:
b - A byte
i - the start index
j - the stop index
Returns:
A bitStream

and

public bitStream and(bitStream b)
Apply and method between this bitStream and a bitStream b

Parameters:
b - a bitStream
Returns:
A bitStream

or

public bitStream or(bitStream b)
Apply or method between this bitStream and a bitStream b

Parameters:
b - a bitStream
Returns:
A bitStream

xor

public bitStream xor(bitStream b)
Apply xor method between this bitStream and a bitStream b

Parameters:
b - a bitStream
Returns:
A bitStream

and

public bitStream and(bitStream b,
                     int ind)
Apply and method between this bitStream and a bitStream b from the index i

Parameters:
b - a bitStream
ind - an integer value
Returns:
A bitStream

or

public bitStream or(bitStream b,
                    int ind)
Apply or method between this bitStream and a bitStream b from the index i

Parameters:
b - a bitStream
ind - an integer value
Returns:
A bitStream

xor

public bitStream xor(bitStream b,
                     int ind)
Apply xor method between this bitStream and a bitStream b from the index i

Parameters:
b - a bitStream
ind - an integer value
Returns:
A bitStream

not

public bitStream not()
Apply or method between this bitStream and a bitStream b

Returns:
A bitStream

toString

public java.lang.String toString()
Make a String from the bitStream

Overrides:
toString in class java.lang.Object
Returns:
A String