- // This is not perfect for unusual bases, eg base 6 has 2.6 bits, so is
- // slightly biased toward having leading zeros, but it's still better
- // than ignoring it completely.
- // TODO: revise this, it seems very fishy. For example, in base 10, there are
- // 8 opportunities to start with 0 but only 2 to start with 1
- var firstInt = base.ints[0];
- var firstIntBits = Math.floor(Math.log2(firstInt))+1;
- var maxFirstIntBits = Math.floor(Math.log2(base.asInt-1))+1;
- var missingFirstIntBits = maxFirstIntBits - firstIntBits;
- var firstIntLeadingZeros = "";
- for (var i=0; i<missingFirstIntBits; i++) {
- binLeadingZeros += "0";
+ // This is not perfect for unusual bases, so is only done for bases
+ // of 2^n, eg octal or hexadecimal
+ if (base.asInt == 16) {
+ var firstInt = base.ints[0];
+ var firstIntBits = firstInt.toString(2).length;
+ var maxFirstIntBits = (base.asInt-1).toString(2).length;
+ var missingFirstIntBits = maxFirstIntBits - firstIntBits;
+ for (var i=0; i<missingFirstIntBits; i++) {
+ binLeadingZeros += "0";
+ }