Example usage for java.lang Integer lowestOneBit

List of usage examples for java.lang Integer lowestOneBit

Introduction

In this page you can find the example usage for java.lang Integer lowestOneBit.

Prototype

public static int lowestOneBit(int i) 

Source Link

Document

Returns an int value with at most a single one-bit, in the position of the lowest-order ("rightmost") one-bit in the specified int value.

Usage

From source file:Main.java

public static void main(String[] args) {

    System.out.println(Integer.lowestOneBit(10));
}

From source file:MainClass.java

public static void main(String args[]) {
    int n = 170;/*from  w ww  .j  a  v a  2  s. c o m*/

    System.out.println("Lowest one bit: " + Integer.lowestOneBit(n));

    System.out.println("Number of leading zeros : " + Integer.numberOfLeadingZeros(n));

    System.out.println("Number of trailing zeros : " + Integer.numberOfTrailingZeros(n));

    System.out.println("\nBeginning with the value 1, " + "rotate left 16 times.");

}

From source file:Bits.java

public static void main(String args[]) {
    int n = 170; // 10101010 
    System.out.println("Value in binary: 10101010");

    System.out.println("Number of one bits: " + Integer.bitCount(n));

    System.out.println("Highest one bit: " + Integer.highestOneBit(n));

    System.out.println("Lowest one bit: " + Integer.lowestOneBit(n));

    System.out.println("Number of leading zeros : " + Integer.numberOfLeadingZeros(n));

    System.out.println("Number of trailing zeros : " + Integer.numberOfTrailingZeros(n));

    System.out.println("\nBeginning with the value 1, " + "rotate left 16 times.");
    n = 1;/*from w  ww. j  ava 2s .  c o  m*/
    for (int i = 0; i < 16; i++) {
        n = Integer.rotateLeft(n, 1);
        System.out.println(n);
    }
}

From source file:MainClass.java

public static void main(String args[]) throws IOException {
    int n = 170; // 10101010

    System.out.println("Value in binary: 10101010");

    System.out.println("Number of one bits: " + Integer.bitCount(n));

    System.out.println("Highest one bit: " + Integer.highestOneBit(n));

    System.out.println("Lowest one bit: " + Integer.lowestOneBit(n));

    System.out.println("Number of leading zeros : " + Integer.numberOfLeadingZeros(n));

    System.out.println("Number of trailing zeros : " + Integer.numberOfTrailingZeros(n));

    System.out.println("\nBeginning with the value 1, " + "rotate left 16 times.");
    n = 1;//from  w w w .ja  v a2  s. c o m
    for (int i = 0; i < 16; i++) {
        n = Integer.rotateLeft(n, 1);
        System.out.println(n);
    }

}

From source file:org.kontalk.util.EncodingUtils.java

/**
 * Get an enum set by parsing an integer which represents a bit array.
 * Source: http://stackoverflow.com/questions/2199399/storing-enumset-in-a-database
 * @param <T> type of elements in enum set
 * @param enumClass enum class to determine the type
 * @param decoded integer decoded as//  w w  w. j a  va 2s .  c  o  m
 * @return an enum set containing the enums specified by the integer
 */
public static <T extends Enum<T>> EnumSet<T> intToEnumSet(Class<T> enumClass, int decoded) {
    EnumSet<T> enumSet = EnumSet.noneOf(enumClass);
    T[] enums = enumClass.getEnumConstants();
    while (decoded != 0) {
        int ordinal = Integer.numberOfTrailingZeros(decoded);
        enumSet.add(enums[ordinal]);
        decoded -= Integer.lowestOneBit(decoded);
    }
    return enumSet;
}

From source file:com.xtructure.xutil.BinaryIndexedTree.java

/**
 * Returns the cumulative frequency up to the given index, inclusive.
 *
 * @param index the index/*from  w  w w .j  a  v a  2s.  c  o m*/
 * @return the cumulative frequency
 */
public long getCumulativeFrequency(int index) {
    long sum = 0;
    int i = index;
    while (i > 0) {
        sum += tree[i];
        i -= Integer.lowestOneBit(i);
    }
    return sum;
}

From source file:mod.rankshank.arbitraria.client.texture.CustomTextureMap.java

@Override
public void loadTexture(IResourceManager resourceManager) throws IOException {
    this.deleteGlTexture();
    initMissingImage();/*  w  w  w  . j  a v a  2s .co  m*/
    int i = Minecraft.getGLMaximumTextureSize();
    Stitcher stitcher = new Stitcher(i, i, 0, this.mipmapLevels);
    this.mapUploadedSprites.clear();
    this.mapRegisteredSprites.clear();
    animationList.clear();

    registrars.forEach(icon -> icon.onRegister(loc -> registerSprite(loc)));

    int j = Integer.MAX_VALUE;
    int k = 1 << this.mipmapLevels;

    ProgressManager.ProgressBar bar = ProgressManager.push("Texture" + TEXTURE_KEY.toString() + "stitching",
            this.mapRegisteredSprites.size());

    for (Map.Entry<String, TextureAtlasSprite> entry : this.mapRegisteredSprites.entrySet()) {
        TextureAtlasSprite textureatlassprite = entry.getValue();
        ResourceLocation resourcelocation = this.getResourceLocation(textureatlassprite);
        bar.step(resourcelocation.getResourcePath());
        IResource iresource = null;

        if (textureatlassprite.hasCustomLoader(resourceManager, resourcelocation)) {
            if (textureatlassprite.load(resourceManager, resourcelocation)) {
                continue;
            }
        } else
            try {
                PngSizeInfo pngsizeinfo = PngSizeInfo
                        .makeFromResource(resourceManager.getResource(resourcelocation));
                iresource = resourceManager.getResource(resourcelocation);
                boolean flag = iresource.getMetadata("animation") != null;
                textureatlassprite.loadSprite(pngsizeinfo, flag);
            } catch (RuntimeException runtimeexception) {
                //LOGGER.error("Unable to parse metadata from {}", new Object[] {resourcelocation, runtimeexception});
                FMLClientHandler.instance().trackBrokenTexture(resourcelocation, runtimeexception.getMessage());
                continue;
            } catch (IOException ioexception) {
                //LOGGER.error("Using missing texture, unable to load {}", new Object[] {resourcelocation, ioexception});
                FMLClientHandler.instance().trackMissingTexture(resourcelocation);
                continue;
            } finally {
                IOUtils.closeQuietly(iresource);
            }

        j = Math.min(j, Math.min(textureatlassprite.getIconWidth(), textureatlassprite.getIconHeight()));
        int squarCheck = Math.min(Integer.lowestOneBit(textureatlassprite.getIconWidth()),
                Integer.lowestOneBit(textureatlassprite.getIconHeight()));

        if (squarCheck < k) {
            Arbitraria.log("TEXTURE DERP @" + textureatlassprite.getIconName());
        }

        stitcher.addSprite(textureatlassprite);
    }

    ProgressManager.pop(bar);
    int l = Math.min(j, k);
    int i1 = MathHelper.log2(l);

    missing.generateMipmaps(this.mipmapLevels);
    stitcher.addSprite(missing);
    bar = ProgressManager.push("Texture creation", 2);

    bar.step("Stitching");
    stitcher.doStitch();

    bar.step("Allocating GL texture");
    TextureUtil.allocateTextureImpl(this.getGlTextureId(), this.mipmapLevels, stitcher.getCurrentWidth(),
            stitcher.getCurrentHeight());
    Map<String, TextureAtlasSprite> map = Maps.newHashMap(this.mapRegisteredSprites);

    ProgressManager.pop(bar);
    bar = ProgressManager.push("Texture mipmap and upload", stitcher.getStichSlots().size());

    for (TextureAtlasSprite stitchingSprite : stitcher.getStichSlots()) {
        bar.step(stitchingSprite.getIconName());
        if (stitchingSprite == this.missing || this.generateMipmaps(resourceManager, stitchingSprite)) {
            String s = stitchingSprite.getIconName();
            map.remove(s);
            this.mapUploadedSprites.put(s, stitchingSprite);

            try {
                TextureUtil.uploadTextureMipmap(stitchingSprite.getFrameTextureData(0),
                        stitchingSprite.getIconWidth(), stitchingSprite.getIconHeight(),
                        stitchingSprite.getOriginX(), stitchingSprite.getOriginY(), false, false);
            } catch (Throwable throwable) {
                CrashReport crashreport = CrashReport.makeCrashReport(throwable, "Stitching texture atlas");
                CrashReportCategory crashreportcategory = crashreport
                        .makeCategory("Texture being stitched together");
                crashreportcategory.addCrashSection("Atlas path", this.TEXTURE_KEY);
                crashreportcategory.addCrashSection("Sprite", stitchingSprite);
                throw new ReportedException(crashreport);
            }

            if (stitchingSprite.hasAnimationMetadata()) {
                this.animationList.add(stitchingSprite);
            }
        }
    }
}

From source file:com.xtructure.xutil.BinaryIndexedTree.java

/**
 * Updates the frequency of the given index in this
 * {@link BinaryIndexedTree} by adding the given count.
 * //from www  . j av  a  2 s .co m
 * @param index the index
 * @param count the count
 * @return the new frequency at the given index
 * @throws IllegalArgumentException
 *             if update would introduce a negative frequency to this
 *             {@link BinaryIndexedTree}
 */
public long update(int index, long count) {
    validateArg("index", index, isGreaterThanOrEqualTo(1), isLessThanOrEqualTo(maxIndex));
    validateArg("count+freq[index]", count + freq[index], isGreaterThanOrEqualTo(0l));
    freq[index] += count;
    int i = index;
    while (i <= maxIndex) {
        tree[i] += count;
        i += Integer.lowestOneBit(i);
    }
    return freq[index];
}