aboutsummaryrefslogtreecommitdiffstats
path: root/ethutil
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-10-08 22:11:36 +0800
committerobscuren <geffobscura@gmail.com>2014-10-08 22:11:36 +0800
commita38dafcc57d296447db9748c8c85df6c58b243fb (patch)
treee92a68835381c3f339303a43028ecf2170916339 /ethutil
parentbd7aca76e1c68ec4d6f76468a250a83f4edd0545 (diff)
downloadgo-tangerine-a38dafcc57d296447db9748c8c85df6c58b243fb.tar
go-tangerine-a38dafcc57d296447db9748c8c85df6c58b243fb.tar.gz
go-tangerine-a38dafcc57d296447db9748c8c85df6c58b243fb.tar.bz2
go-tangerine-a38dafcc57d296447db9748c8c85df6c58b243fb.tar.lz
go-tangerine-a38dafcc57d296447db9748c8c85df6c58b243fb.tar.xz
go-tangerine-a38dafcc57d296447db9748c8c85df6c58b243fb.tar.zst
go-tangerine-a38dafcc57d296447db9748c8c85df6c58b243fb.zip
Moved the To256
Diffstat (limited to 'ethutil')
-rw-r--r--ethutil/big.go13
1 files changed, 13 insertions, 0 deletions
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**