Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions lib/bn.js
Original file line number Diff line number Diff line change
Expand Up @@ -480,16 +480,16 @@
var w = this.words[i];
var word = (((w << off) | carry) & 0xffffff).toString(16);
carry = (w >>> (24 - off)) & 0xffffff;
if (carry !== 0 || i !== this.length - 1) {
out = zeros[6 - word.length] + word + out;
} else {
out = word + out;
}
off += 2;
if (off >= 26) {
off -= 26;
i--;
}
if (carry !== 0 || i !== this.length - 1) {
out = zeros[6 - word.length] + word + out;
} else {
out = word + out;
}
}
if (carry !== 0) {
out = carry.toString(16) + out;
Expand Down
10 changes: 10 additions & 0 deletions test/utils-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ var BN = require('../').BN;

describe('BN.js/Utils', function () {
describe('.toString()', function () {
describe('hex no padding', function () {
it('should have same length as input', function () {
var hex = '1';
for (var i = 1; i <= 128; i++) {
var n = new BN(hex, 16);
assert.equal(n.toString(16).length, i);
hex = hex + '0';
}
});
});
describe('binary padding', function () {
it('should have a length of 256', function () {
var a = new BN(0);
Expand Down