From a38dafcc57d296447db9748c8c85df6c58b243fb Mon Sep 17 00:00:00 2001 From: obscuren Date: Wed, 8 Oct 2014 16:11:36 +0200 Subject: Moved the To256 --- ethutil/big.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'ethutil') diff --git a/ethutil/big.go b/ethutil/big.go index ec263b818..d8f54ad10 100644 --- a/ethutil/big.go +++ b/ethutil/big.go @@ -34,6 +34,19 @@ func BigD(data []byte) *big.Int { return n } +// To256 +// +// "cast" the big int to a 256 big int (i.e., limit to) +var tt256 = new(big.Int).Sub(new(big.Int).Lsh(big.NewInt(1), 256), big.NewInt(1)) + +func To256(x *big.Int) { + x.And(x, tt256) + + if x.Cmp(new(big.Int)) < 0 { + x.SetInt64(0) + } +} + // Big to bytes // // Returns the bytes of a big integer with the size specified by **base** -- cgit v1.2.3