package com.primeFactorizer;

/**
 * This class implements several bit manipulation functions.
 * @author fpereira
 *
 */
public final class BitManipulator {

  /**
   * Private ctor to avoid instantiation.
   */
  private BitManipulator() { }

  /**
   * Counts the number of bits that are set in the long integer.
   * @param l the input long integer.
   * @return an integer between 0 and 64, representing the number of bits
   * that are set.
   */
  public static byte countNumSet(final long l) {
    byte acc = 0;
    for (long mask = 1; mask != 0; mask <<= 1) {
      acc += ((l & mask) == mask) ? 1 : 0;
    }
    return acc;
  }

}
