1
0
Fork 0

string(): make zero padding work if arg is 0

This commit is contained in:
mfranz 2008-12-22 01:50:48 +00:00
parent 601f1c14c4
commit bab238d58b

View file

@ -29,9 +29,7 @@ var switch = func(n, b, v) n - (test(n, b) - !!v) * bit[b];
# returns number <n> as bit string, zero-padded to <len> digits: # returns number <n> as bit string, zero-padded to <len> digits:
# bits.string(6) -> "110" # bits.string(6) -> "110"
# bits.string(6, 8) -> "00000110" # bits.string(6, 8) -> "00000110"
var string = func(n, len = 0) { var string = func(n, len = 1) {
if (!n)
return '0';
var s = ""; var s = "";
while (n) { while (n) {
var v = int(n / 2); var v = int(n / 2);