byte[] array = new BigInteger("1111000011110001", 2).toByteArray(); byte[] secondArray = new BigInteger("1111000011110001", 2).toByteArray(); if (Arrays.equals(array, secondArray)) { System.out.println("Yup, they're the same!"); }
/** * Converts primitive int value to a form most suitable for encoding. * * @param value primitive value to be encoded * @return object suitable for encoding */ public static Object fromIntValue(int value) { return BigInteger.valueOf(value).toByteArray(); } }
public static Decimal toMetastoreDecimal(BigDecimal decimal) { return new Decimal(ByteBuffer.wrap(decimal.unscaledValue().toByteArray()), (short) decimal.scale()); }
BigInteger max = BigInteger.valueOf(2).pow(255); byte[] target = BigIntegers.asUnsignedByteArray(32, max.divide(new BigInteger(1, difficulty))); (new BigInteger(1, newBlock.getGasLimit()).longValue() * (1024 - 1) + (newBlock.getGasUsed() * 6 / 5)) / 1024); newBlock.getHeader().setGasLimit(BigInteger.valueOf(newGasLimit).toByteArray()); System.out.println("mining: " + new BigInteger(1, testNonce));
if (new BigInteger("1111000011110001", 2).toByteArray() == array)
if (!isNumeric) throw new Error("Wrong test case JSON format"); else { BigInteger value = new BigInteger(val.toString()); try { bos.write(value.toByteArray()); } catch (IOException e) { logger.error("should not happen", e); byte[] data = ByteUtil.bigIntegerToBytes(BigInteger.valueOf((Long) val)); try { bos.write(data);
private byte[] bigIntToByteArray( final int i ) { BigInteger bigInt = BigInteger.valueOf(i); return bigInt.toByteArray(); }
private byte[] convertFromDecimal(Schema schema, BigDecimal decimal) { final LogicalType logicalType = schema.getLogicalType(); if (logicalType instanceof LogicalTypes.Decimal) { final LogicalTypes.Decimal decimalType = (LogicalTypes.Decimal) logicalType; // rescale to target type final BigDecimal rescaled = decimal.setScale(decimalType.getScale(), BigDecimal.ROUND_UNNECESSARY); // byte array must contain the two's-complement representation of the // unscaled integer value in big-endian byte order return decimal.unscaledValue().toByteArray(); } else { throw new RuntimeException("Unsupported decimal type."); } }
/** * This method converts a HEX string to Byte[] * * @param hex: the HEX string * @return: a byte array */ private static byte[] hexStr2Bytes(String hex) { // Adding one byte to get the right conversion // Values starting with "0" can be converted byte[] bArray = new BigInteger("10" + hex, 16).toByteArray(); // Copy all the REAL bytes, not the "first" byte[] ret = new byte[bArray.length - 1]; for (int i = 0; i < ret.length; i++) ret[i] = bArray[i + 1]; return ret; }
appendZeros(endOS, startOS.size() - endOS.size()); BigInteger min = new BigInteger(startOS.toByteArray()); BigInteger max = new BigInteger(endOS.toByteArray()); BigInteger mid = max.subtract(min).divide(BigInteger.valueOf(2)).add(min); byte[] ba = mid.toByteArray();
protected void getValues(Object object, Object[] values) { int [] accuracy = (int []) object; for (int i = 0; i < 3; i++) { if (i > 0 && (accuracy[i] < 0 || accuracy[i] > 999)) { throw new RuntimeException("Time-stamp accuracy value is incorrect: " + accuracy[i]); } values[i] = BigInteger.valueOf(accuracy[i]).toByteArray(); } } };
public static Decimal createThriftDecimal(String s) { BigDecimal d = new BigDecimal(s); return new Decimal((short) d.scale(), ByteBuffer.wrap(d.unscaledValue().toByteArray())); }
String s="f263575e7b00a977a8e9a37e08b9c215feb9bfb2f992b2b8f11e"; byte[] b = new BigInteger(s,16).toByteArray();
variance = new BigInteger(begin - fixed, _context.random()); else variance = BigInteger.ZERO; variance = variance.or(BigInteger.valueOf(fixedBits).shiftLeft(begin - fixed)); } else { nonz = BigInteger.valueOf(nz); } else { nonz = new BigInteger(numNonZero, _context.random()); } while (nonz.equals(BigInteger.ZERO)); byte data[] = variance.toByteArray(); T key = makeKey(data); byte[] hash = DataHelper.xor(key.getData(), _us.getData());
private static void formatBigIntegerBinary(final long value, final byte[] buf, final int offset, final int length, final boolean negative) { final BigInteger val = BigInteger.valueOf(value); final byte[] b = val.toByteArray(); final int len = b.length; final int off = offset + length - len; System.arraycopy(b, 0, buf, off, len); final byte fill = (byte) (negative ? 0xff : 0); for (int i = offset + 1; i < off; i++) { buf[i] = fill; } }
public void set(int index, BigDecimal value) { byte[] bytes = value.unscaledValue().toByteArray(); set(index, bytes, 0, bytes.length); }
public static byte[] parseMacAddress(String macAddress){ if(macAddress != null && !macAddress.equals("null") && !macAddress.isEmpty()){ String[] bytes = macAddress.split(":"); byte[] parsed = new byte[bytes.length]; for(int x = 0; x < bytes.length; x++){ BigInteger temp = new BigInteger(bytes[x], 16); byte[] raw = temp.toByteArray(); parsed[x] = raw[raw.length - 1]; } return parsed; } return null; }
for (int i = 0; i < numColumns; i++) { Cell cell = Cell.create(PtBytes.toBytes("row"), PtBytes.toBytes("column" + i)); BigInteger cellValue = BigInteger.valueOf(i); initTransaction.put(TABLE, ImmutableMap.of(cell, cellValue.toByteArray())); List<BigInteger> initialValues = Lists.newArrayList(); for (int j = 0; j < numColumns; j++) { initialValues.add(BigInteger.valueOf(j)); Cell cell = Cell.create(PtBytes.toBytes("row"), PtBytes.toBytes("column" + columnNumber)); BigInteger newValue = BigInteger.valueOf(random.nextInt(100000)); t.put(TABLE, ImmutableMap.of(cell, newValue.toByteArray())); writtenValues.get(transactionIndex).set(columnNumber, newValue); } else { byte[] storedValue = t.get(TABLE, Collections.singleton(cell)).get(cell); BigInteger expectedValue = writtenValues.get(transactionIndex).get(columnNumber); assertEquals(expectedValue, new BigInteger(storedValue));
public byte[] getBytes() { byte[] numberBytes = BigInteger.valueOf(blockNumber).toByteArray(); byte[] txBytes = transaction.getEncoded(); byte[] bytes = new byte[1 + numberBytes.length + txBytes.length]; bytes[0] = (byte) numberBytes.length; System.arraycopy(numberBytes, 0, bytes, 1, numberBytes.length); System.arraycopy(txBytes, 0, bytes, 1 + numberBytes.length, txBytes.length); return bytes; }
public void setSafe(int index, BigDecimal value) { byte[] bytes = value.unscaledValue().toByteArray(); setSafe(index, bytes, 0, bytes.length); }