Java Code Examples for org.ethereum.util.ByteUtil#copyToArray()

The following examples show how to use org.ethereum.util.ByteUtil#copyToArray() . 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 File: DataWord.java    From nuls with MIT License 5 votes vote down vote up
public DataWord addmod(DataWord word1, DataWord word2) {
    if (word2.isZero()) {
        return ZERO;
    }

    BigInteger result = value().add(word1.value()).mod(word2.value());
    return new DataWord(ByteUtil.copyToArray(result.and(MAX_VALUE)));
}
 
Example 2
Source File: DataWord.java    From nuls with MIT License 5 votes vote down vote up
public DataWord sMod(DataWord word) {

        if (word.isZero()) {
            return ZERO;
        }

        BigInteger result = sValue().abs().mod(word.sValue().abs());
        result = (sValue().signum() == -1) ? result.negate() : result;

        return new DataWord(ByteUtil.copyToArray(result.and(MAX_VALUE)));
    }
 
Example 3
Source File: DataWord.java    From nuls-v2 with MIT License 5 votes vote down vote up
public DataWord div(DataWord word) {

        if (word.isZero()) {
            return ZERO;
        }

        BigInteger result = value().divide(word.value());
        return new DataWord(ByteUtil.copyToArray(result.and(MAX_VALUE)));
    }
 
Example 4
Source File: DataWord.java    From nuls-v2 with MIT License 5 votes vote down vote up
public DataWord sDiv(DataWord word) {

        if (word.isZero()) {
            return ZERO;
        }

        BigInteger result = sValue().divide(word.sValue());
        return new DataWord(ByteUtil.copyToArray(result.and(MAX_VALUE)));
    }
 
Example 5
Source File: DataWord.java    From nuls with MIT License 5 votes vote down vote up
/**
 * Shift right, this is signed, while input arg is treated as unsigned
 *
 * @param arg
 * @return this >> arg
 */
public DataWord shiftRightSigned(DataWord arg) {
    if (arg.value().compareTo(BigInteger.valueOf(MAX_POW)) >= 0) {
        if (this.isNegative()) {
            return DataWord.ONE.negate();
        } else {
            return DataWord.ZERO;
        }
    }

    BigInteger result = sValue().shiftRight(arg.intValueSafe());
    return new DataWord(ByteUtil.copyToArray(result.and(MAX_VALUE)));
}
 
Example 6
Source File: DataWord.java    From nuls with MIT License 5 votes vote down vote up
public DataWord div(DataWord word) {

        if (word.isZero()) {
            return ZERO;
        }

        BigInteger result = value().divide(word.value());
        return new DataWord(ByteUtil.copyToArray(result.and(MAX_VALUE)));
    }
 
Example 7
Source File: DataWord.java    From nuls with MIT License 5 votes vote down vote up
public DataWord mod(DataWord word) {

        if (word.isZero()) {
            return ZERO;
        }

        BigInteger result = value().mod(word.value());
        return new DataWord(ByteUtil.copyToArray(result.and(MAX_VALUE)));
    }
 
Example 8
Source File: DataWord.java    From nuls-v2 with MIT License 5 votes vote down vote up
public DataWord sMod(DataWord word) {

        if (word.isZero()) {
            return ZERO;
        }

        BigInteger result = sValue().abs().mod(word.sValue().abs());
        result = (sValue().signum() == -1) ? result.negate() : result;

        return new DataWord(ByteUtil.copyToArray(result.and(MAX_VALUE)));
    }
 
Example 9
Source File: DataWord.java    From ethereumj with MIT License 5 votes vote down vote up
public void div(DataWord word)  {

        if (word.isZero()) {
            this.and(ZERO);
            return;
        }

		BigInteger result = value().divide(word.value());
		this.data = ByteUtil.copyToArray(result.and(MAX_VALUE));
    }
 
Example 10
Source File: DataWord.java    From nuls with MIT License 5 votes vote down vote up
/**
 * Shift right, both this and input arg are treated as unsigned
 *
 * @param arg
 * @return this >> arg
 */
public DataWord shiftRight(DataWord arg) {
    if (arg.value().compareTo(BigInteger.valueOf(MAX_POW)) >= 0) {
        return DataWord.ZERO;
    }

    BigInteger result = value().shiftRight(arg.intValueSafe());
    return new DataWord(ByteUtil.copyToArray(result.and(MAX_VALUE)));
}
 
Example 11
Source File: DataWord.java    From ethereumj with MIT License 5 votes vote down vote up
public void sMod(DataWord word) {

        if (word.isZero()) {
            this.and(ZERO);
            return;
        }

        BigInteger result = sValue().remainder(word.sValue());
        this.data = ByteUtil.copyToArray(result.and(MAX_VALUE));
    }
 
Example 12
Source File: DataWord.java    From nuls with MIT License 5 votes vote down vote up
public DataWord mulmod(DataWord word1, DataWord word2) {

        if (this.isZero() || word1.isZero() || word2.isZero()) {
            return ZERO;
        }

        BigInteger result = value().multiply(word1.value()).mod(word2.value());
        return new DataWord(ByteUtil.copyToArray(result.and(MAX_VALUE)));
    }
 
Example 13
Source File: DataWord.java    From nuls with MIT License 4 votes vote down vote up
public DataWord exp(DataWord word) {
    BigInteger newData = value().modPow(word.value(), _2_256);
    return new DataWord(ByteUtil.copyToArray(newData));
}
 
Example 14
Source File: DataWord.java    From nuls with MIT License 4 votes vote down vote up
public DataWord add2(DataWord word) {
    BigInteger result = value().add(word.value());
    return new DataWord(ByteUtil.copyToArray(result.and(MAX_VALUE)));
}
 
Example 15
Source File: DataWord.java    From ethereumj with MIT License 4 votes vote down vote up
public void add2(DataWord word) {
BigInteger result = value().add(word.value());
this.data = ByteUtil.copyToArray(result.and(MAX_VALUE));
  }
 
Example 16
Source File: DataWord.java    From ethereumj with MIT License 4 votes vote down vote up
public void sub(DataWord word) {
BigInteger result = value().subtract(word.value());        
this.data = ByteUtil.copyToArray(result.and(MAX_VALUE));
  }
 
Example 17
Source File: DataWord.java    From ethereumj with MIT License 4 votes vote down vote up
public void mulmod(DataWord word1, DataWord word2) {
BigInteger result = value().multiply(word1.value()).mod(word2.value());
      this.data = ByteUtil.copyToArray(result.and(MAX_VALUE));
  }
 
Example 18
Source File: DataWord.java    From ethereumj with MIT License 4 votes vote down vote up
public void exp(DataWord word) {
BigInteger result = value().modPow(word.value(), _2_256);
this.data = ByteUtil.copyToArray(result);
  }
 
Example 19
Source File: DataWord.java    From nuls-v2 with MIT License 4 votes vote down vote up
public DataWord mul(DataWord word) {
    BigInteger result = value().multiply(word.value());
    return new DataWord(ByteUtil.copyToArray(result.and(MAX_VALUE)));
}
 
Example 20
Source File: DataWord.java    From nuls-v2 with MIT License 4 votes vote down vote up
public DataWord add2(DataWord word) {
    BigInteger result = value().add(word.value());
    return new DataWord(ByteUtil.copyToArray(result.and(MAX_VALUE)));
}