
com.hazelcast.internal.tpcengine.util.BitUtil Maven / Gradle / Ivy
The newest version!
/*
* Copyright (c) 2008-2024, Hazelcast, Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.hazelcast.internal.tpcengine.util;
public final class BitUtil {
public static final int SIZEOF_BYTE = Byte.BYTES;
public static final int SIZEOF_CHAR = Character.BYTES;
public static final int SIZEOF_INT = Integer.BYTES;
public static final int SIZEOF_LONG = Long.BYTES;
public static final int SIZEOF_FLOAT = Float.BYTES;
public static final int SIZEOF_DOUBLE = Double.BYTES;
private BitUtil() {
}
/**
* Fast method of finding the next power of 2 greater than or equal to the supplied value.
*
* If the value is <= 0 then 1 will be returned.
*
* This method is not suitable for {@link Integer#MIN_VALUE} or numbers greater than 2^30.
*
* @param value from which to search for next power of 2
* @return The next power of 2 or the value itself if it is a power of 2
*/
@SuppressWarnings("checkstyle:MagicNumber")
public static int nextPowerOfTwo(final int value) {
return 1 << (32 - Integer.numberOfLeadingZeros(value - 1));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy