Class Representation

java.lang.Object
  extended by Representation

 class Representation
extends java.lang.Object

A class that holds a representation of a binary number along with assorted metadata about the number. Two representations are needed to hold a fixed point number. Ints are used for each bit so each can take on the values of 1, 0 or -1. -1 values come into play for CSD numbers.

Author:
Craig A. Lindley

Field Summary
private  boolean guardBit
           
private  int numberBits
           
private  int[] representation
           
private  boolean signBit
           
 
Constructor Summary
Representation(int numberBits)
          Class constructor creates storage for the representation of the specified number of bits and sets the the two bits of metadata to false.
 
Method Summary
 java.lang.String formatRepresentation(boolean showMetadata)
           
private  void fromLong(long value)
          Make the representation conform to the long value
 int getBit(int bitNumber)
           
 boolean getGuardBit()
           
 int getNumberBits()
           
 int[] getRepresentation()
           
 boolean getSignBit()
           
 void onesComp()
          Performs a 1's compliment operation on the representation.
 void setBit(int bitNumber, int bit)
           
 void setGuardBit(boolean guardBit)
           
 void setRepresentation(int[] representation)
           
 void setSignBit(boolean signBit)
           
private  long toLong()
          Create a long value from the representation
 java.lang.String toString()
           
 void twosComp()
          Performs a 2's compliment operation on the representation.
 boolean zero()
          Determine if the representation has no bits set
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

numberBits

private int numberBits

signBit

private boolean signBit

guardBit

private boolean guardBit

representation

private int[] representation
Constructor Detail

Representation

public Representation(int numberBits)
Class constructor creates storage for the representation of the specified number of bits and sets the the two bits of metadata to false.

Parameters:
numberBits - number of bits in the representation
Method Detail

zero

public boolean zero()
Determine if the representation has no bits set

Returns:
true if all bits of representation are zero; false if not

onesComp

public void onesComp()
Performs a 1's compliment operation on the representation. This is done by inverting each bit.


toLong

private long toLong()
Create a long value from the representation

Returns:
long int representing the representation

fromLong

private void fromLong(long value)
Make the representation conform to the long value

Parameters:
value - long value that the representation should conform to

twosComp

public void twosComp()
Performs a 2's compliment operation on the representation. This is done by inverting each bit and adding one. This operation converts a positive representation into a negative one and vise versa.


getNumberBits

public int getNumberBits()

getSignBit

public boolean getSignBit()

setSignBit

public void setSignBit(boolean signBit)

getGuardBit

public boolean getGuardBit()

setGuardBit

public void setGuardBit(boolean guardBit)

getRepresentation

public int[] getRepresentation()

setRepresentation

public void setRepresentation(int[] representation)

getBit

public int getBit(int bitNumber)

setBit

public void setBit(int bitNumber,
                   int bit)

formatRepresentation

public java.lang.String formatRepresentation(boolean showMetadata)

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object