Shifts bits of a BitSet object one place to the left. - Java java.util

Java examples for java.util:BitSet

Description

Shifts bits of a BitSet object one place to the left.

Demo Code


//package com.java2s;

import java.util.BitSet;

public class Main {
    /**/*from   ww  w.j a va  2  s . co  m*/
     * Shifts bits of a BitSet object one place to the left.
     * Stores new value in the same BitSet.
     *
     * @param s Shifted BitSet object.
     * @param length Length of binary number.
     * @return BitSet s after shifting.
     */
    public static BitSet shiftLeft(BitSet s, int length) {
        for (int i = length; i > 0; i--) {
            s.set(i, s.get(i - 1));
        }
        s.set(0, false);

        return s;
    }
}

Related Tutorials