Here you can find the source of minSignedIntForBitSize(final int bitSize)
Parameter | Description |
---|---|
bitSize | A number of bits in [1,32]. |
Parameter | Description |
---|---|
IllegalArgumentException | if the specified number of bits is out of range. |
public static int minSignedIntForBitSize(final int bitSize)
//package com.java2s; //License from project: Open Source License public class Main { /**/*www . ja v a2s . com*/ * @param bitSize * A number of bits in [1,32]. * @return The min signed int value that can be stored over the specified number of bits. * @throws IllegalArgumentException * if the specified number of bits is out of range. */ public static int minSignedIntForBitSize(final int bitSize) { checkBitSizeForSignedInt(bitSize); return minSignedIntForBitSize_noCheck(bitSize); } /** * @return True if does not throw. * @throws IllegalArgumentException * if a signed int value can't be read over the specified number of bits, i.e. if it is not in [1,32]. */ public static boolean checkBitSizeForSignedInt(final int bitSize) { if (!isValidBitSizeForSignedInt(bitSize)) { throw new IllegalArgumentException( "bit size [" + bitSize + "] must be in [1,32] for signed int values"); } return true; } private static int minSignedIntForBitSize_noCheck(final int bitSize) { // i.e. (-1<<(bitSize-1)) return Integer.MIN_VALUE >> 32 - bitSize; } /** * @return True if a signed int value can be read over the specified number of bits, i.e. if it is in [1,32], false * otherwise. */ public static boolean isValidBitSizeForSignedInt(final int bitSize) { return bitSize > 0 && bitSize <= 32; } }