本文整理了Java中java.math.BigInteger.toByteArray()
方法的一些代码示例,展示了BigInteger.toByteArray()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。BigInteger.toByteArray()
方法的具体详情如下:
包路径:java.math.BigInteger
类名称:BigInteger
方法名:toByteArray
[英]Returns the two's complement representation of this BigInteger in a byte array.
[中]返回字节数组中此BigInteger的两个补码表示形式。
代码示例来源:origin: stackoverflow.com
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!");
}
代码示例来源:origin: robovm/robovm
/**
* 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();
}
}
代码示例来源:origin: prestodb/presto
public static Decimal toMetastoreDecimal(BigDecimal decimal)
{
return new Decimal(ByteBuffer.wrap(decimal.unscaledValue().toByteArray()), (short) decimal.scale());
}
代码示例来源:origin: ethereum/ethereumj
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));
代码示例来源:origin: stackoverflow.com
if (new BigInteger("1111000011110001", 2).toByteArray() == array)
代码示例来源:origin: ethereum/ethereumj
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);
代码示例来源:origin: stackoverflow.com
private byte[] bigIntToByteArray( final int i ) {
BigInteger bigInt = BigInteger.valueOf(i);
return bigInt.toByteArray();
}
代码示例来源:origin: apache/flink
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.");
}
}
代码示例来源:origin: hs-web/hsweb-framework
/**
* 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;
}
代码示例来源:origin: apache/accumulo
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();
代码示例来源:origin: robovm/robovm
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();
}
}
};
代码示例来源:origin: apache/hive
public static Decimal createThriftDecimal(String s) {
BigDecimal d = new BigDecimal(s);
return new Decimal((short) d.scale(), ByteBuffer.wrap(d.unscaledValue().toByteArray()));
}
代码示例来源:origin: stackoverflow.com
String s="f263575e7b00a977a8e9a37e08b9c215feb9bfb2f992b2b8f11e";
byte[] b = new BigInteger(s,16).toByteArray();
代码示例来源:origin: i2p/i2p.i2p
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());
代码示例来源:origin: org.apache.ant/ant
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;
}
}
代码示例来源:origin: apache/drill
public void set(int index, BigDecimal value) {
byte[] bytes = value.unscaledValue().toByteArray();
set(index, bytes, 0, bytes.length);
}
代码示例来源:origin: cSploit/android
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;
}
代码示例来源:origin: palantir/atlasdb
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));
代码示例来源:origin: ethereum/ethereumj
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;
}
代码示例来源:origin: apache/drill
public void setSafe(int index, BigDecimal value) {
byte[] bytes = value.unscaledValue().toByteArray();
setSafe(index, bytes, 0, bytes.length);
}
内容来源于网络,如有侵权,请联系作者删除!