git ssb

0+

wanderer🌟 / js-primea-hypervisor



Commit 7ffc2533d01f9b747d1e93544fa339e5573f9b12

Introduce U256 class

Alex Beregszaszi committed on 8/13/2016, 1:46:37 AM
Parent: a514f42929dd5562af01038f0e55d3674936da43

Files changed

u256.jsadded
u256.jsView
@@ -1,0 +1,39 @@
1+const BN = require('bn.js')
2+const ethUtils = require('ethereumjs-util')
3+
4+module.exports = class U256 {
5+ constructor (value) {
6+ if ((typeof value === 'string') && ethUtils.isHexPrefixed(value)) {
7+ this._value = new BN(value, 16)
8+ } else {
9+ this._value = new BN(value, 10)
10+ }
11+ }
12+
13+ toString (radix = 10) {
14+ if (radix === 16) {
15+ return '0x' + this._value.toString(16)
16+ }
17+ return this._value.toString(radix)
18+ }
19+
20+ toBuffer () {
21+ return this._value.toBuffer('be', 32)
22+ }
23+
24+ subi (u256) {
25+ this._value.subi(u256._value)
26+ }
27+
28+ addi (u256) {
29+ this._value.addi(u256._value)
30+ }
31+
32+ lt (u256) {
33+ return this._value.lt(u256._value)
34+ }
35+
36+ gt (u256) {
37+ return this._value.gt(u256._value)
38+ }
39+}

Built with git-ssb-web