cds.util
Class Integers

java.lang.Object
  extended bycds.util.Integers

public class Integers
extends java.lang.Object

Static methods dealing with int variables

Version:
1.0 May 2003, 1.1 Feb 2004 MW: add nbBytes()
Author:
Marc Wenger/CDS

Field Summary
private static int[] mask10
           
static int[] pow10
           
 
Constructor Summary
Integers()
           
 
Method Summary
static int extract(int num, int pos, int lg)
          Extracts from an integer lg bits from a given position
static int insert(int num, int n, int pos, int lg)
          Inserts in a integer another number on nbits at a given position
static int nbBytes(int num)
          Computes the number of bytes needed by the integer (from 1 to 4)
static int nbdigits(int num)
          Computes the number of decimal digits of an integer
static int parseInt(java.lang.String str)
          Parse an integer string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

pow10

public static final int[] pow10

mask10

private static final int[] mask10
Constructor Detail

Integers

public Integers()
Method Detail

nbdigits

public static int nbdigits(int num)
Computes the number of decimal digits of an integer

Parameters:
num - integer
Returns:
the number of decimal digits

nbBytes

public static int nbBytes(int num)
Computes the number of bytes needed by the integer (from 1 to 4)

Parameters:
num - integer
Returns:
the number of bytes

insert

public static int insert(int num,
                         int n,
                         int pos,
                         int lg)
                  throws java.text.ParseException
Inserts in a integer another number on nbits at a given position

Parameters:
num - integer in which to insert n
n - number toinsert (lg bits will be used)
pos - position from which the number n must be inserted (0 is the leftmost bit, 31 is the last possible position to insert 1 bit)
lg - number of bits from n to insert. pos+lg <= 32
Returns:
the new value of num
Throws:
java.text.ParseException - if the number is incorrect

extract

public static int extract(int num,
                          int pos,
                          int lg)
Extracts from an integer lg bits from a given position

Parameters:
num - integer fromwhich to extract the bits
pos - position from which the bits should be extracted (0 is the leftmost bit, 31 is the last possible position to extract 1 bit)
lg - number of bits to extract. pos+lg <= 32
Returns:
the extracted bits returned as an integer

parseInt

public static int parseInt(java.lang.String str)
                    throws java.lang.NumberFormatException
Parse an integer string. Does the same as Integer.parseInt(), but is more flexible and accepts '+' sign !

Parameters:
str - string to analyse as a number. The accepted syntax is:
spacesspacesspaces
Returns:
the integer number
Throws:
java.lang.NumberFormatException - if the number fails to be analyzed