Java Code Examples for java.math.BigInteger#shortValue()
The following examples show how to use
java.math.BigInteger#shortValue() .
These examples are extracted from open source projects.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: hasor File: OperatorUtils.java License: Apache License 2.0 | 6 votes |
private static Number newReal(int realType, BigInteger value) { switch (realType) { case BOOL: return BigInteger.ZERO.compareTo(value) == 0 ? 0 : 1; case BYTE: return value.byteValue(); case SHORT: return value.shortValue(); case CHAR: case INT: return value.intValue(); case LONG: return value.longValue(); default: return value; } }
Example 2
Source Project: zserio File: CastUInt64ToUInt8Test.java License: BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void uint8ValueUsingUInt64Value() { final BigInteger uint64Value = new BigInteger("FFFFFFFFFFFFFFFE", 16); final CastUInt64ToUInt8Expression castUInt64ToUInt8Expression = new CastUInt64ToUInt8Expression(uint64Value, false); final short expectedUInt8Value = uint64Value.shortValue(); assertEquals(expectedUInt8Value, castUInt64ToUInt8Expression.funcUint8Value()); }
Example 3
Source Project: mumu File: StringUtil.java License: Apache License 2.0 | 5 votes |
public static String baseString(BigInteger num, int base) { String str = "", digit = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; if (num.shortValue() == 0) { return ""; } else { BigInteger valueOf = BigInteger.valueOf(base); str = baseString(num.divide(valueOf), base); return str + digit.charAt(num.mod(valueOf).shortValue()); } }
Example 4
Source Project: SI File: TlvDecoder.java License: BSD 2-Clause "Simplified" License | 5 votes |
/** * Decodes a byte array into an integer value. */ public static Number decodeInteger(byte[] value) throws TlvException { BigInteger bi = new BigInteger(value); if (value.length == 1) { return bi.byteValue(); } else if (value.length <= 2) { return bi.shortValue(); } else if (value.length <= 4) { return bi.intValue(); } else if (value.length <= 8) { return bi.longValue(); } else { throw new TlvException("Invalid length for an integer value: " + value.length); } }
Example 5
Source Project: SI File: TlvDecoder.java License: BSD 2-Clause "Simplified" License | 5 votes |
/** * Decodes a byte array into an integer value. */ public static Number decodeInteger(byte[] value) throws TlvException { BigInteger bi = new BigInteger(value); if (value.length == 1) { return bi.byteValue(); } else if (value.length <= 2) { return bi.shortValue(); } else if (value.length <= 4) { return bi.intValue(); } else if (value.length <= 8) { return bi.longValue(); } else { throw new TlvException("Invalid length for an integer value: " + value.length); } }
Example 6
Source Project: batfish File: Ip6.java License: Apache License 2.0 | 5 votes |
private static String asIpv6AddressString(BigInteger ipv6AddressAsBigInteger) { BigInteger remainder = ipv6AddressAsBigInteger; String[] pieces = new String[8]; for (int i = 0; i < 8; i++) { int mask = (int) remainder.shortValue() & 0xFFFF; pieces[7 - i] = String.format("%x", mask); remainder = remainder.shiftRight(16); } return StringUtils.join(pieces, ":"); }
Example 7
Source Project: jackcess File: DefaultFunctions.java License: Apache License 2.0 | 4 votes |
@Override protected Value eval1(EvalContext ctx, Value param1) { // strip all whitespace from string String str = ValueSupport.WHITESPACE_PAT.matcher(param1.getAsString(ctx)) .replaceAll(""); if(str.length() == 0) { return ValueSupport.ZERO_D_VAL; } Matcher m = null; if(str.charAt(0) == ValueSupport.NUMBER_BASE_PREFIX) { // see if we can parse as a radix format BigInteger bi = null; if((m = ValueSupport.HEX_PAT.matcher(str)).find()) { bi = ValueSupport.parseIntegerString(m.group(), 16); } else if((m = ValueSupport.OCTAL_PAT.matcher(str)).find()) { bi = ValueSupport.parseIntegerString(m.group(), 8); } if(bi != null) { // this function works differently than normal string to number // conversion. it seems to coerce these values to a short/long int // depending on the size of the number (which creates // positive/negative values dependent on the value length) int iVal = ((bi.bitLength() <= 16) ? bi.shortValue() : bi.intValue()); return ValueSupport.toValue((double)iVal); } } else { // parse as normal "decimal" number. if((m = ValueSupport.NUMBER_PAT.matcher(str)).find()) { BigDecimal bd = new BigDecimal(m.group()); return ValueSupport.toValue(bd.doubleValue()); } } return ValueSupport.ZERO_D_VAL; }
Example 8
Source Project: Java-Coding-Problems File: Main.java License: MIT License | 3 votes |
public static void main(String[] args) { BigInteger nr = BigInteger.valueOf(Long.MAX_VALUE); long nrLong = nr.longValue(); System.out.println(nr + " as long is: " + nrLong); int nrInt = nr.intValue(); System.out.println(nr + " as int is: " + nrInt); short nrShort = nr.shortValue(); System.out.println(nr + " as short is: " + nrShort); byte nrByte = nr.byteValue(); System.out.println(nr + " as byte is: " + nrByte); long nrExactLong = nr.longValueExact(); // ok System.out.println(nr + " as exact long is: " + nrExactLong); int nrExactInt = nr.intValueExact(); // ArithmeticException System.out.println(nr + " as exact int is: " + nrExactInt); short nrExactShort = nr.shortValueExact(); // ArithmeticException System.out.println(nr + " as exact short is: " + nrExactShort); byte nrExactByte = nr.byteValueExact(); // ArithmeticException System.out.println(nr + " as exact byte is: " + nrExactByte); }
Example 9
Source Project: CPE552-Java File: UShort.java License: GNU General Public License v3.0 | 3 votes |
/** * Throw exception if value out of range (long version) * * @param value Value to check * @return value if it is in range * @throws ArithmeticException if value is out of range */ public static short checkSigned(BigInteger value) throws ArithmeticException { if (value.compareTo(BigInteger.ZERO) < 0 || value.intValue() > MAX_VALUE) { throw new ArithmeticException("Value is out of range : " + value); } return value.shortValue(); }
Example 10
Source Project: CPE552-Java File: ULong.java License: GNU General Public License v3.0 | 3 votes |
/** * Throw exception if value out of range (long version) * * @param value Value to check * @return value if it is in range * @throws ArithmeticException if value is out of range */ public static short checkSigned(BigInteger value) throws ArithmeticException { if (value.compareTo(BigInteger.ZERO) < 0 || value.intValue() > MAX_VALUE) { throw new ArithmeticException("Value is out of range : " + value); } return value.shortValue(); }
Example 11
Source Project: glm File: UShort.java License: MIT License | 3 votes |
/** * Throw exception if value out of range (long version) * * @param value Value to check * @return value if it is in range * @throws ArithmeticException if value is out of range */ public static short checkSigned(BigInteger value) throws ArithmeticException { if (value.compareTo(BigInteger.ZERO) < 0 || value.intValue() > MAX_VALUE) { throw new ArithmeticException("Value is out of range : " + value); } return value.shortValue(); }
Example 12
Source Project: glm File: ULong.java License: MIT License | 3 votes |
/** * Throw exception if value out of range (long version) * * @param value Value to check * @return value if it is in range * @throws ArithmeticException if value is out of range */ public static short checkSigned(BigInteger value) throws ArithmeticException { if (value.compareTo(BigInteger.ZERO) < 0 || value.intValue() > MAX_VALUE) { throw new ArithmeticException("Value is out of range : " + value); } return value.shortValue(); }
Example 13
Source Project: CPE552-Java File: UShort.java License: GNU General Public License v3.0 | 2 votes |
/** * Create an <code>unsigned short</code> * * @param value */ public UShort(BigInteger value) { this.value = value.shortValue(); }
Example 14
Source Project: glm File: UShort.java License: MIT License | 2 votes |
/** * Create an <code>unsigned short</code> * * @param value */ public UShort(BigInteger value) { this.value = value.shortValue(); }