List of usage examples for java.math BigInteger intValue
public int intValue()
From source file:Main.java
public static void main(String[] args) { // assign values to bi1, bi2 BigInteger bi1 = new BigInteger("123"); BigInteger bi2 = new BigInteger("987654321"); // assign the integer values of bi1, bi2 to i1, i2 Integer i1 = bi1.intValue(); Integer i2 = bi2.intValue();/*from ww w. j a v a 2s. c o m*/ System.out.println(i1); System.out.println(i2); }
From source file:Main.java
/** * Utility method to check validity of the provided code. The version must be base 36 encoded. * * @param code the code string to check. * @param expectedLength the length the code must be. * @param codeVersionStartIndex the start index (INCLUSIVE) to get the code version from. * @param codeVersionEndIndex the end index (EXCLUSIVE) to get the code version from. * @param expectedVersion the version code that the code's version should be checked against. * @return true if the code passes the expected length and version checks. */// w ww .j a v a2 s. c o m public static boolean isValidCode(@NonNull final String code, final int expectedLength, final int codeVersionStartIndex, final int codeVersionEndIndex, final int expectedVersion) { boolean isValid = true; if (code.length() != expectedLength) { isValid = false; } else { final String versionCode = code.substring(codeVersionStartIndex, codeVersionEndIndex); final BigInteger i = new BigInteger(versionCode, Character.MAX_RADIX); if (i.intValue() != expectedVersion) { isValid = false; } } return isValid; }
From source file:Main.java
public static boolean isGoodPrime(byte[] prime, int g) { if (!(g >= 2 && g <= 7)) { return false; }//from w w w . j a v a 2 s . co m if (prime.length != 256 || prime[0] >= 0) { return false; } BigInteger dhBI = new BigInteger(1, prime); if (g == 2) { // p mod 8 = 7 for g = 2; BigInteger res = dhBI.mod(BigInteger.valueOf(8)); if (res.intValue() != 7) { return false; } } else if (g == 3) { // p mod 3 = 2 for g = 3; BigInteger res = dhBI.mod(BigInteger.valueOf(3)); if (res.intValue() != 2) { return false; } } else if (g == 5) { // p mod 5 = 1 or 4 for g = 5; BigInteger res = dhBI.mod(BigInteger.valueOf(5)); int val = res.intValue(); if (val != 1 && val != 4) { return false; } } else if (g == 6) { // p mod 24 = 19 or 23 for g = 6; BigInteger res = dhBI.mod(BigInteger.valueOf(24)); int val = res.intValue(); if (val != 19 && val != 23) { return false; } } else if (g == 7) { // p mod 7 = 3, 5 or 6 for g = 7. BigInteger res = dhBI.mod(BigInteger.valueOf(7)); int val = res.intValue(); if (val != 3 && val != 5 && val != 6) { return false; } } String hex = bytesToHex(prime); if (hex.equals( "C71CAEB9C6B1C9048E6C522F70F13F73980D40238E3E21C14934D037563D930F48198A0AA7C14058229493D22530F4DBFA336F6E0AC925139543AED44CCE7C3720FD51F69458705AC68CD4FE6B6B13ABDC9746512969328454F18FAF8C595F642477FE96BB2A941D5BCD1D4AC8CC49880708FA9B378E3C4F3A9060BEE67CF9A4A4A695811051907E162753B56B0F6B410DBA74D8A84B2A14B3144E0EF1284754FD17ED950D5965B4B9DD46582DB1178D169C6BC465B0D6FF9CA3928FEF5B9AE4E418FC15E83EBEA0F87FA9FF5EED70050DED2849F47BF959D956850CE929851F0D8115F635B105EE2E4E15D04B2454BF6F4FADF034B10403119CD8E3B92FCC5B")) { return true; } BigInteger dhBI2 = dhBI.subtract(BigInteger.valueOf(1)).divide(BigInteger.valueOf(2)); return !(!dhBI.isProbablePrime(30) || !dhBI2.isProbablePrime(30)); }
From source file:Main.java
public static byte[] generateJSF(BigInteger g, BigInteger h) { int digits = Math.max(g.bitLength(), h.bitLength()) + 1; byte[] jsf = new byte[digits]; BigInteger k0 = g, k1 = h; int j = 0, d0 = 0, d1 = 0; while (k0.signum() > 0 || k1.signum() > 0 || d0 > 0 || d1 > 0) { int n0 = (k0.intValue() + d0) & 7, n1 = (k1.intValue() + d1) & 7; int u0 = n0 & 1; if (u0 != 0) { u0 -= (n0 & 2);/*from w w w .j a v a2 s .co m*/ if ((n0 + u0) == 4 && (n1 & 3) == 2) { u0 = -u0; } } int u1 = n1 & 1; if (u1 != 0) { u1 -= (n1 & 2); if ((n1 + u1) == 4 && (n0 & 3) == 2) { u1 = -u1; } } if ((d0 << 1) == 1 + u0) { d0 = 1 - d0; } if ((d1 << 1) == 1 + u1) { d1 = 1 - d1; } k0 = k0.shiftRight(1); k1 = k1.shiftRight(1); jsf[j++] = (byte) ((u0 << 4) | (u1 & 0xF)); } // Reduce the JSF array to its actual length if (jsf.length > j) { jsf = trim(jsf, j); } return jsf; }
From source file:Main.java
public static byte[] generateJSF(BigInteger g, BigInteger h) { int digits = Math.max(g.bitLength(), h.bitLength()) + 1; byte[] jsf = new byte[digits]; BigInteger k0 = g, k1 = h; int j = 0, d0 = 0, d1 = 0; int offset = 0; while ((d0 | d1) != 0 || k0.bitLength() > offset || k1.bitLength() > offset) { int n0 = ((k0.intValue() >>> offset) + d0) & 7, n1 = ((k1.intValue() >>> offset) + d1) & 7; int u0 = n0 & 1; if (u0 != 0) { u0 -= (n0 & 2);/*w ww. j a v a2 s . c o m*/ if ((n0 + u0) == 4 && (n1 & 3) == 2) { u0 = -u0; } } int u1 = n1 & 1; if (u1 != 0) { u1 -= (n1 & 2); if ((n1 + u1) == 4 && (n0 & 3) == 2) { u1 = -u1; } } if ((d0 << 1) == 1 + u0) { d0 ^= 1; } if ((d1 << 1) == 1 + u1) { d1 ^= 1; } if (++offset == 30) { offset = 0; k0 = k0.shiftRight(30); k1 = k1.shiftRight(30); } jsf[j++] = (byte) ((u0 << 4) | (u1 & 0xF)); } // Reduce the JSF array to its actual length if (jsf.length > j) { jsf = trim(jsf, j); } return jsf; }
From source file:com.clustercontrol.repository.util.RepositoryUtil.java
/** * BigIntegerIP(IPv6)?????/*from w w w . ja v a 2s . c o m*/ * @param argInt IPv6? * @return String */ public static String bigIntToIpV6(BigInteger argInt) { StringBuilder str = new StringBuilder(); for (int i = 15; i >= 0; i--) { int shift = 8 * i; Integer n = 0xff; BigInteger num = argInt.shiftRight(shift).and(new BigInteger(n.toString())); int intNum = num.intValue(); String s = Integer.toHexString(intNum); if (s.length() < 2) { s = "0" + s; } str.append(s); if (i > 0 && i < 15) { int f = i % 2; str.append(f == 0 ? ":" : ""); } } return str.toString(); }
From source file:com.aurel.track.exchange.docx.exporter.StyleUtil.java
/** * Gets the styleIDs by outline levels://from ww w .java 2 s . c o m * Heading 1 is lvl 0 There are 9 levels, so Heading 9 will be lvl 8 * @param mainDocumentPart * @return */ static Map<Integer, String> getInterestingStyleIDs(MainDocumentPart mainDocumentPart) { Map<Integer, String> outlinelevelToStyleName = new HashMap<Integer, String>(); StyleDefinitionsPart styleDefinitionsPart = mainDocumentPart.getStyleDefinitionsPart(); Styles styles = null; try { styles = styleDefinitionsPart.getContents(); } catch (Docx4JException e) { LOGGER.error("Getting the styles contents failed with " + e.getMessage()); LOGGER.debug(ExceptionUtils.getStackTrace(e)); } if (styles != null) { for (Style style : styles.getStyle()) { String sytleID = style.getStyleId(); Style.Name name = style.getName(); String styleName = name.getVal(); if (styleName != null) { PPr pPr = style.getPPr(); if (pPr != null) { OutlineLvl outlineLvl = pPr.getOutlineLvl(); if (outlineLvl != null && styleName.startsWith(STANDARD_STYLE_NAMES.HEADING_NAME)) { //sometimes other styles like Title have OutlineLvl BigInteger level = outlineLvl.getVal(); outlinelevelToStyleName.put(Integer.valueOf(level.intValue()), sytleID); LOGGER.debug("StyleID for level " + level + " is: " + sytleID); } } } } } return outlinelevelToStyleName; }
From source file:Main.java
public static byte[] generateJSF(BigInteger g, BigInteger h) { byte[] jsf = new byte[(Math.max(g.bitLength(), h.bitLength()) + 1)]; BigInteger k0 = g; BigInteger k1 = h;//from www . ja v a2s . c om int d0 = 0; int d1 = 0; int offset = 0; int j = 0; while (true) { if ((d0 | d1) == 0 && k0.bitLength() <= offset && k1.bitLength() <= offset) { break; } int n0 = ((k0.intValue() >>> offset) + d0) & 7; int n1 = ((k1.intValue() >>> offset) + d1) & 7; int u0 = n0 & 1; if (u0 != 0) { u0 -= n0 & 2; if (n0 + u0 == 4 && (n1 & 3) == 2) { u0 = -u0; } } int u1 = n1 & 1; if (u1 != 0) { u1 -= n1 & 2; if (n1 + u1 == 4 && (n0 & 3) == 2) { u1 = -u1; } } if ((d0 << 1) == u0 + 1) { d0 ^= 1; } if ((d1 << 1) == u1 + 1) { d1 ^= 1; } offset++; if (offset == 30) { offset = 0; k0 = k0.shiftRight(30); k1 = k1.shiftRight(30); } int j2 = j + 1; jsf[j] = (byte) ((u0 << 4) | (u1 & 15)); j = j2; } if (jsf.length > j) { return trim(jsf, j); } return jsf; }
From source file:com.aurel.track.exchange.docx.exporter.StyleUtil.java
/** * Gets styles//w ww.j a v a2 s . c o m * @param mainDocumentPart * @param paragaphStylesSet * @param characterStylesSet * @param outlinelevelToStyleName */ public static void getStyles(MainDocumentPart mainDocumentPart, Map<String, String> paragaphStylesSet, Map<String, String> characterStylesSet, Map<Integer, String> outlinelevelToStyleName) { StyleDefinitionsPart styleDefinitionsPart = mainDocumentPart.getStyleDefinitionsPart(); Styles styles = null; try { styles = styleDefinitionsPart.getContents(); } catch (Docx4JException e) { LOGGER.error("Getting the styles contents failed with " + e.getMessage()); LOGGER.debug(ExceptionUtils.getStackTrace(e)); } if (styles != null) { for (Style style : styles.getStyle()) { String styleID = style.getStyleId(); String type = style.getType(); Style.Name name = style.getName(); String styleName = name.getVal(); if (styleName != null) { if (STYLE_TYPE.CHARACTER.equals(type)) { characterStylesSet.put(styleName, styleID); LOGGER.debug("Character styleID " + styleID + " with name " + styleName); } else { if (STYLE_TYPE.PARAGRAPH.endsWith(type)) { paragaphStylesSet.put(styleName, styleID); LOGGER.debug("Paragaph styleID " + styleID + " with name " + styleName); PPr pPr = style.getPPr(); if (pPr != null) { OutlineLvl outlineLvl = pPr.getOutlineLvl(); if (outlineLvl != null && styleName.startsWith(STANDARD_STYLE_NAMES.HEADING_NAME)) { //sometimes other styles like Title have OutlineLvl BigInteger level = outlineLvl.getVal(); outlinelevelToStyleName.put(Integer.valueOf(level.intValue()), styleID); LOGGER.debug("Heading StyleID for level " + level + " is: " + styleID); } } } } } } } }
From source file:org.codice.ddf.spatial.ogc.wps.process.endpoint.Validator.java
/** * @param inputs/*from www .j a v a 2 s . c o m*/ * @param inputDescription * @throws WpsException */ public static void validateProcessInputsMinMaxOccurs(List<Data> inputs, DataDescription inputDescription) { if (CollectionUtils.isEmpty(inputs)) { if (BigInteger.ZERO.equals(inputDescription.getMinOccurs())) { return; } else { throw new WpsException("Too few input items have been specified.", "TooFewInputs", inputDescription.getId()); } } BigInteger maxOccurs = inputDescription.getMaxOccurs() == null ? BigInteger.ONE : inputDescription.getMaxOccurs(); if (inputs.size() > maxOccurs.intValue()) { throw new WpsException("Too many input items have been specified.", "TooManyInputs", inputDescription.getId()); } BigInteger minOccurs = inputDescription.getMinOccurs() == null ? BigInteger.ONE : inputDescription.getMinOccurs(); if (inputs.size() < minOccurs.intValue()) { throw new WpsException("Too few input items have been specified.", "TooFewInputs", inputDescription.getId()); } inputs.forEach(input -> validateProcessInputData(input, inputDescription)); }