Merge pull request #28 from braydonf/bn-fromstring
Add base option for BN.fromString
This commit is contained in:
commit
60b07b5b3c
|
@ -21,9 +21,9 @@ BN.fromNumber = function(n) {
|
|||
return new BN(n);
|
||||
};
|
||||
|
||||
BN.fromString = function(str) {
|
||||
BN.fromString = function(str, base) {
|
||||
$.checkArgument(_.isString(str));
|
||||
return new BN(str);
|
||||
return new BN(str, base);
|
||||
};
|
||||
|
||||
BN.fromBuffer = function(buf, opts) {
|
||||
|
|
|
@ -79,9 +79,9 @@ describe('BN', function() {
|
|||
it('should make BN from a string', function() {
|
||||
BN.fromString('5').toString().should.equal('5');
|
||||
});
|
||||
it('should work with 7fffff0000000000000000000000000000000000000000000000000000000000', function() {
|
||||
BN.fromString('7fffff0000000000000000000000000000000000000000000000000000000000')
|
||||
.toString().should.equal('7fffff0000000000000000000000000000000000000000000000000000000000');
|
||||
it('should work with hex string', function() {
|
||||
BN.fromString('7fffff0000000000000000000000000000000000000000000000000000000000', 16)
|
||||
.toString(16).should.equal('7fffff0000000000000000000000000000000000000000000000000000000000');
|
||||
});
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue