Something went wrong. Try again.
🌱 A minimal programming language and compiler. git.urbach.dev/cli/q
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647fromInt(x int, base int, buffer []byte) -> []byte { assert base >= 2 assert base <= 16 negative := x < 0 end := buffer.ptr + buffer.len tmp := end
loop { digit := x % base x /= base tmp -= 1 [tmp] = "FEDCBA9876543210123456789ABCDEF"[digit+15]
if x == 0 { if negative { tmp -= 1 [tmp] = '-' }
return []byte{ ptr: tmp, len: end - tmp as uint, } } }}
fromInt(x uint, base uint, buffer []byte) -> []byte { assert base >= 2 assert base <= 16 end := buffer.ptr + buffer.len tmp := end
loop { digit := x % base x /= base tmp -= 1 [tmp] = "0123456789ABCDEF"[digit]
if x == 0 { return []byte{ ptr: tmp, len: end - tmp as uint, } } }}