# How to display UInt in decimal instead of hexadecimal

**URL:** <https://discourse.julialang.org/t/how-to-display-uint-in-decimal-instead-of-hexadecimal/25756>\
**Category:** General Usage\
**Tags:** question, repl\
**Created:** [June 27, 2019, 9:27am UTC](https://discourse.julialang.org/t/how-to-display-uint-in-decimal-instead-of-hexadecimal/25756 "2019-06-27T09:27:45Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Robert\_Honig](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/robert_honig/32/4930_2.png) [@Robert\_Honig](https://discourse.julialang.org/u/Robert_Honig)\
**Post date:** [June 27, 2019, 9:27am UTC](https://discourse.julialang.org/t/how-to-display-uint-in-decimal-instead-of-hexadecimal/25756/1 "2019-06-27T09:27:45Z")

</div>

So far, whenever I had to work with `UInt` variables, I wanted to see their value in decimal. Unfortunately, the REPL displays `UInt` values in hexadecimal:

```julia
julia> a = rand(UInt16, 5)
5-element Array{UInt16,1}:
 0x8128
 0x0dcf
 0x5f0d
 0x5dc1
 0x9beb

```

Is there a way to permanently change this behavior? I am aware of this temporary solution:

```julia
julia> Int.(a)
5-element Array{Int64,1}:
 33064
  3535
 24333
 24001
 39915

```

(This quickly gets tedious over time and with structs of UInts.)

---

<div class="post-metadata">

**Author:** ![cormullion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cormullion/32/49131_2.png) [@cormullion](https://discourse.julialang.org/u/cormullion)\
**Post date:** [June 27, 2019, 9:49am UTC](https://discourse.julialang.org/t/how-to-display-uint-in-decimal-instead-of-hexadecimal/25756/2 "2019-06-27T09:49:21Z")

</div>

I’m not sure if it’s a good idea but you could play with this idea:

 ![14](https://global.discourse-cdn.com/julialang/original/3X/1/2/12261f20aafe3d2eb87d4d45cd14f0a794984d08.png)

(The yellow reminds you that they’re a bit fishy…)

---

<div class="post-metadata">

**Author:** ![jw3126](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jw3126/32/3086_2.png) [@jw3126](https://discourse.julialang.org/u/jw3126)\
**Post date:** [June 27, 2019, 12:23pm UTC](https://discourse.julialang.org/t/how-to-display-uint-in-decimal-instead-of-hexadecimal/25756/3 "2019-06-27T12:23:16Z")

</div>

Doing this is [type piracy](https://docs.julialang.org/en/v1/manual/style-guide/index.html#Avoid-type-piracy-1). I would say doing so in a repl session/script etc. is okay. But I would not do it in a package.

---

<div class="post-metadata">

**Author:** ![cormullion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cormullion/32/49131_2.png) [@cormullion](https://discourse.julialang.org/u/cormullion)\
**Post date:** [June 27, 2019, 12:51pm UTC](https://discourse.julialang.org/t/how-to-display-uint-in-decimal-instead-of-hexadecimal/25756/4 "2019-06-27T12:51:38Z")

</div>

fishy indeed.

 ![image](https://global.discourse-cdn.com/julialang/original/3X/6/b/6bd1e8ce1ae3f24de72b67586fa668b24da0bd4b.jpeg)

---

<div class="post-metadata">

**Author:** ![gdkrmr](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gdkrmr/32/2791_2.png) [@gdkrmr](https://discourse.julialang.org/u/gdkrmr)\
**Post date:** [June 27, 2019, 1:15pm UTC](https://discourse.julialang.org/t/how-to-display-uint-in-decimal-instead-of-hexadecimal/25756/5 "2019-06-27T13:15:40Z")

</div>

```julia
julia> string(0x0A, base = 10)
"10"

```

If you want to have `UInt`s printed in base 10, I think you will have to overwrite `Base.show`.

---

<div class="post-metadata">

**Author:** ![Amin\_Yahyaabadi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/amin_yahyaabadi/32/9826_2.png) [@Amin\_Yahyaabadi](https://discourse.julialang.org/u/Amin_Yahyaabadi)\
**Post date:** [October 28, 2019, 8:31am UTC](https://discourse.julialang.org/t/how-to-display-uint-in-decimal-instead-of-hexadecimal/25756/6 "2019-10-28T08:31:42Z")

</div>

```julia
Base.show(io::IO, x::T) where {T<:Union{UInt, UInt128, UInt64,
UInt32, UInt16, UInt8}} = Base.print(io, x)

```

---

<div class="post-metadata">

**Author:** ![RoyiAvital](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/royiavital/32/571_2.png) [@RoyiAvital](https://discourse.julialang.org/u/RoyiAvital)\
**Post date:** [October 12, 2022, 12:23pm UTC](https://discourse.julialang.org/t/how-to-display-uint-in-decimal-instead-of-hexadecimal/25756/7 "2022-10-12T12:23:36Z")

</div>

The trick with `Int.(arrayUInt)` will work only in cases you have bits to spare. For instance converting `UInt32` to `Int64` or `UInt64` to `Int128`.

Is there another trick which isn’t limited by this? Something like the trick by @Amin_Yahyaabadi yet works for the current print only and not the whole session?

One can use `BigInt.(arrayUInt)` which should work. I wonder if there are more options.
