# \[ANN\] \`Undigits.jl\` undoes \`Base.digits\` (not registered)

**URL:** https://discourse.julialang.org/t/ann-undigits-jl-undoes-base-digits-not-registered/132791
**Category:** Performance
**Created:** [September 30, 2025, 5:46pm UTC](https://discourse.julialang.org/t/ann-undigits-jl-undoes-base-digits-not-registered/132791 "2025-09-30T17:46:30Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![jlapeyre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jlapeyre/32/4514_2.png) [@jlapeyre](https://discourse.julialang.org/u/jlapeyre)
#### Post date: [September 30, 2025, 5:46pm UTC](https://discourse.julialang.org/t/ann-undigits-jl-undoes-base-digits-not-registered/132791/1 "2025-09-30T17:46:30Z")

</div>

[Undigits.jl](https://github.com/jlapeyre/Undigits.jl)

This package provides `undigits`, the reverse of `digits`.

```julia
julia> undigits([2, 4])
42

julia> undigits([2, 4]; rev=true)
24

julia> undigits(UInt8, [1, 0, 1, 1]; base=2)
0x0d

julia> n = UInt16(17); undigits(typeof(n), digits(n)) === n
true

```

I wanted this today and could not recall which overly-ambitious package I had stuck it in. I even thought it might be in `Undigits.jl`, so I searched.

I found it and put it in a standalone package. I have not made a registration request.

---

<div class="post-metadata">

### Author: ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)
#### Post date: [September 30, 2025, 6:02pm UTC](https://discourse.julialang.org/t/ann-undigits-jl-undoes-base-digits-not-registered/132791/2 "2025-09-30T18:02:54Z")

</div>

It’s not very intuitive (and doesn’t catch overflow), but you can also spell this `evalpoly(base, digits)`.

> <https://github.com/JuliaLang/julia/issues/40393#issuecomment-815816135>
>
> We have the \`digits\` function for \`integer -\> digits\`:
> 
> \`\`\`Julia
> julia\> digit…s(1234)
> 4-element Vector{Int64}:
> 4
> 3
> 2
> 1
> \`\`\`
> 
> However, we don't have the "inverse function" that implements \`digits -\> integer\`. A top of the head implementation (ignoring \`base\` and \`pad\` keyword arguments) could be something like (cc: @ararslan)
> 
> \`\`\`julia
> digits2integer(digits) = sum(((i, x),) -\> x \* 10^(i - 1), pairs(digits))
> \`\`\`
> 
> (Very ugly alternative: \`parse(Int, join(digits))\`)
> 
> such that
> 
> \`\`\`Julia
> julia\> digits2integer(digits(1234))
> 1234
> \`\`\`
> 
> I feel we should have something like this, what do you think?
> 
> Potentially issues/difficulties:
> \* Type stability: what if the digits don't fit into \`Int\`. We would need to dynamically extend to \`BigInt\` or similar which is obviously suboptimal.
> \* Need to find a good name (as always).
> \* More?

---

<div class="post-metadata">

### Author: ![jlapeyre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jlapeyre/32/4514_2.png) [@jlapeyre](https://discourse.julialang.org/u/jlapeyre)
#### Post date: [September 30, 2025, 6:21pm UTC](https://discourse.julialang.org/t/ann-undigits-jl-undoes-base-digits-not-registered/132791/3 "2025-09-30T18:21:34Z")

</div>

I forgot about that issue. `evalpoly(base, v)` is probably not too hard to think of if you use Julia frequently. It’s certainly economical.

Looking at the issue again, I see that this package

[FromDigits.jl](https://github.com/FedericoStra/FromDigits.jl)

exists.
