Merge pull request #1253 from maraoz/bn-fromstring

add base to BN.fromString
This commit is contained in:
Braydon Fuller 2015-06-01 13:35:21 -04:00
commit 5d77ff7c58
2 changed files with 6 additions and 2 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,6 +79,10 @@ describe('BN', function() {
it('should make BN from a string', function() {
BN.fromString('5').toString().should.equal('5');
});
it('should work with hex string', function() {
BN.fromString('7fffff0000000000000000000000000000000000000000000000000000000000', 16)
.toString(16).should.equal('7fffff0000000000000000000000000000000000000000000000000000000000');
});
});
describe('#toString', function() {