1 /* Copyright (C) 2000 Free Software Foundation
3 This file is part of libgcj.
5 This software is copyrighted work licensed under the terms of the
6 Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
12 * Simple transparent utility class that can be used to perform bit
13 * mask extent calculations.
15 public final class BitMaskExtent
17 /** The number of the least significant bit of the bit mask extent. */
18 public byte leastSignificantBit;
20 /** The number of bits in the bit mask extent. */
24 * Set the bit mask. This will calculate and set the leastSignificantBit
25 * and bitWidth fields.
27 * @see #leastSignificantBit
30 public void setMask(long mask)
32 leastSignificantBit = 0;
34 if (mask == 0) return;
35 long shiftMask = mask;
36 for (; (shiftMask&1) == 0; shiftMask >>>=1) leastSignificantBit++;
37 for (; (shiftMask&1) != 0; shiftMask >>>=1) bitWidth++;
40 throw new IllegalArgumentException("mask must be continuous");
44 * Calculate the bit mask based on the values of the
45 * leastSignificantBit and bitWidth fields.
49 return ((1<<bitWidth)-1) << leastSignificantBit;