Add base option for BN.fromString

This commit is contained in:
Braydon Fuller 2015-05-27 14:11:43 -04:00
parent e2542866d1
commit a03e6b9385
2 changed files with 5 additions and 5 deletions

View File

@ -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) {

View File

@ -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');
});
});