protected BigInteger castValueToEncode(Object value) throws DataTypeEncodeException {
		if (value instanceof BigInteger) {
			return (BigInteger) value;
		}
		if (value instanceof Scalar) {
			// I'll take the scalar's signedness and neglect this type's....
			return ((Scalar) value).getBigInteger();
		}
		if (value instanceof Character) {
			int numeric = Character.getNumericValue((Character) value);
			if (numeric < 0) {
				throw new DataTypeEncodeException("Character cannot be converted to number", value,
					this);
			}
			return BigInteger.valueOf(numeric);
		}
		if (value instanceof Byte || value instanceof Short || value instanceof Integer ||
			value instanceof Long) {
			Number number = (Number) value;
			BigInteger signedVal = BigInteger.valueOf(number.longValue());
			if (isSigned() || signedVal.signum() >= 0) {
				return signedVal;
			}
			return signedVal.add(BigInteger.ONE.shiftLeft(getBitCount(number.getClass())));
		}
		throw new DataTypeEncodeException("Unsupported value type", value, this);
	}
Get the number of bits in the integral type

@param type the type
@return the number of bits
Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/data/AbstractIntegerDataType.java