net.cscott.jutil

Class Util

public abstract class Util extends Object

Miscellaneous static utility functions.

Version: $Id: Util.java,v 1.1 2003/03/20 01:58:20 cananian Exp $

Author: C. Scott Ananian

Method Summary
static intffs(int v)
Find first set (least significant bit).
static intffs(long v)
Find first set (least significant bit).
static intfls(int v)
Find last set (most significant bit).
static intfls(long v)
Find last set (most significant bit).
static longgcd(long u, long v)
Returns the greatest common divisor of a pair of numbers.
static intgcd(int u, int v)
Returns the greatest common divisor of a pair of numbers.
static intlog2c(int v)
Returns ceil(log2(n))
static intpopcount(int v)
Return the number of ones in the binary representation of the value of the argument.
static intpopcount(long v)
Return the number of ones in the binary representation of the value of the argument.
static StringrepeatString(String s, int n)
Repeat a given string a certain number of times.
static intzerocount(int v)
Return the number of zeros in the binary representation of the value of the argument.
static intzerocount(long v)
Return the number of zeros in the binary representation of the value of the argument.

Method Detail

ffs

public static final int ffs(int v)
Find first set (least significant bit).

Returns: the first bit set in the argument. ffs(0)==0 and ffs(1)==1.

ffs

public static final int ffs(long v)
Find first set (least significant bit).

Returns: the first bit set in the argument. ffs(0)==0 and ffs(1)==1.

fls

public static final int fls(int v)
Find last set (most significant bit).

Returns: the last bit set in the argument. fls(0)==0 and fls(1)==1.

fls

public static final int fls(long v)
Find last set (most significant bit).

Returns: the last bit set in the argument. fls(0)==0 and fls(1)==1.

gcd

public static final long gcd(long u, long v)
Returns the greatest common divisor of a pair of numbers.

gcd

public static final int gcd(int u, int v)
Returns the greatest common divisor of a pair of numbers.

log2c

public static final int log2c(int v)
Returns ceil(log2(n))

popcount

public static final int popcount(int v)
Return the number of ones in the binary representation of the value of the argument.

popcount

public static final int popcount(long v)
Return the number of ones in the binary representation of the value of the argument.

repeatString

public static final String repeatString(String s, int n)
Repeat a given string a certain number of times.

Returns: a string consisting of s repeated n times.

zerocount

public static final int zerocount(int v)
Return the number of zeros in the binary representation of the value of the argument.

zerocount

public static final int zerocount(long v)
Return the number of zeros in the binary representation of the value of the argument.
Copyright © 2003 C. Scott Ananian