diff options
Diffstat (limited to 'tex/context/base/l-number.lua')
-rw-r--r-- | tex/context/base/l-number.lua | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/tex/context/base/l-number.lua b/tex/context/base/l-number.lua index 8a7340905..08acb6040 100644 --- a/tex/context/base/l-number.lua +++ b/tex/context/base/l-number.lua @@ -7,7 +7,8 @@ if not modules then modules = { } end modules ['l-number'] = { } local tostring = tostring -local format, floor, insert, match = string.format, math.floor, table.insert, string.match +local format, floor, insert, match = string.format, math.floor, string.match +local concat, insert = table.concat, table.insert local lpegmatch = lpeg.match number = number or { } @@ -75,3 +76,16 @@ end function number.clearbit(x, p) return hasbit(x, p) and x - p or x end + +function number.tobitstring(n) + if n == 0 then + return "0" + else + local t = { } + while n > 0 do + insert(t,1,n % 2 > 0 and 1 or 0) + n = floor(n/2) + end + return concat(t) + end +end |