cse378.util
Class Bits

java.lang.Object
  extended by cse378.util.Bits

public class Bits
extends java.lang.Object


Constructor Summary
Bits()
           
 
Method Summary
static int extract(int num, int start, int width)
          extract the value of a bitfield,
static int extractSafe(int num, int start, int width)
          extract the value of a bitfield
static byte log2(int num)
          compute the base 2 log of an integer
static int mask(int num, int maskBits, int start)
          extract the value of a bitfield
static java.lang.String toBinaryString(int i)
           
static java.lang.String toBinaryString(int i, int width)
           
static java.lang.String toHexString(int i)
           
static java.lang.String toHexString(int i, int width)
           
private static java.lang.String toUnsignedString(int i, int shift)
          Convert the integer to an unsigned number.
static int truncate(int num, int bitWidth)
           
static int truncateSafe(int num, int bitWidth)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Bits

public Bits()
Method Detail

log2

public static byte log2(int num)
compute the base 2 log of an integer

Parameters:
num -
Returns:
b such that 2^b == num (or close)

extractSafe

public static int extractSafe(int num,
                              int start,
                              int width)
extract the value of a bitfield

Parameters:
num -
start - first bit to include
width - number of bits to include
Returns:
bits [end:start] of num as an int

extract

public static int extract(int num,
                          int start,
                          int width)
extract the value of a bitfield,

Parameters:
num -
start - first bit to include
width - number of bits to include
Returns:
bits [end:start] of num as an int

mask

public static int mask(int num,
                       int maskBits,
                       int start)
extract the value of a bitfield

Parameters:
num -
start - first bit to include
end - last bit to include
Returns:
bits [end:start] of num as an int

truncate

public static int truncate(int num,
                           int bitWidth)

truncateSafe

public static int truncateSafe(int num,
                               int bitWidth)

toHexString

public static java.lang.String toHexString(int i)

toHexString

public static java.lang.String toHexString(int i,
                                           int width)

toBinaryString

public static java.lang.String toBinaryString(int i)

toBinaryString

public static java.lang.String toBinaryString(int i,
                                              int width)

toUnsignedString

private static java.lang.String toUnsignedString(int i,
                                                 int shift)
Convert the integer to an unsigned number.