# What determines if integers are formatted as hex or not in the REPL?

**URL:** <https://discourse.julialang.org/t/what-determines-if-integers-are-formatted-as-hex-or-not-in-the-repl/103386>\
**Category:** New to Julia\
**Created:** [August 30, 2023, 8:37pm UTC](https://discourse.julialang.org/t/what-determines-if-integers-are-formatted-as-hex-or-not-in-the-repl/103386 "2023-08-30T20:37:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![frylock](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/frylock/32/50213_2.png) [@frylock](https://discourse.julialang.org/u/frylock)\
**Post date:** [August 30, 2023, 8:37pm UTC](https://discourse.julialang.org/t/what-determines-if-integers-are-formatted-as-hex-or-not-in-the-repl/103386/1 "2023-08-30T20:37:58Z")

</div>

Why is one printed as hex and the other not?  
Also, why does the line number not increase after the first assignment? (doesn’t seem to always do that - just noticed it)

```julia
   _ _ _(_)_ | Documentation: https://docs.julialang.org
  (_) | (_) (_) |
   _ _ _| |_ __ _ | Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` | |
  | | |_| | | | (_| | | Version 1.11.0-DEV.368 (2023-08-30)
 _/ |\ __'_|_|_|\__'_| | Commit 197180d858 (0 days old master)
|__/ |

In [1]: a::UInt32 = 100
Out[1]: 100

In [1]: b::UInt32 = 0xfe0
Out[1]: 0x0fe0

```

EDIT: perhaps it is the UInt32 type? In a new session, adding `a` to `a` gives:

```julia
In [1]: a::UInt32 = 100
Out[1]: 100

In [2]: b::UInt32 = 0xfe0
Out[2]: 0x0fe0

In [3]: a + a
Out[3]: 0x000000c8

```

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [August 30, 2023, 8:55pm UTC](https://discourse.julialang.org/t/what-determines-if-integers-are-formatted-as-hex-or-not-in-the-repl/103386/2 "2023-08-30T20:55:21Z")

</div>

> [@frylock](#):
>
> Why is one printed as hex and the other not?

Because the value of an [assignment expression](https://docs.julialang.org/en/v1/manual/variables/#man-assignment-expressions) is the _right-hand side_. So, in an expression like `a::UInt32 = 100`, the right-hand side is the (signed) `Int` literal value `100`, which prints in decimal by default. Whereas unsigned values print in hexadecimal by default, so if you show `a` or `0xfe0` they display in hexadecimal:

```julia
julia> 100
100

julia> a::UInt32 = 100
100

julia> a
0x00000064

```

---

<div class="post-metadata">

**Author:** ![frylock](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/frylock/32/50213_2.png) [@frylock](https://discourse.julialang.org/u/frylock)\
**Post date:** [August 30, 2023, 8:57pm UTC](https://discourse.julialang.org/t/what-determines-if-integers-are-formatted-as-hex-or-not-in-the-repl/103386/3 "2023-08-30T20:57:49Z")

</div>

And it does indeed mention that fact in [the documentation](https://docs.julialang.org/en/v1/manual/integers-and-floating-point-numbers/). I overlooked.

---

<div class="post-metadata">

**Author:** ![Palli](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/palli/32/3380_2.png) [@Palli](https://discourse.julialang.org/u/Palli)\
**Post date:** [August 30, 2023, 8:58pm UTC](https://discourse.julialang.org/t/what-determines-if-integers-are-formatted-as-hex-or-not-in-the-repl/103386/4 "2023-08-30T20:58:48Z")

</div>

It’s because the right-hand side isn’t unsigned in the former case, and it (using its type) is shown (there Int64). And what is show is nothing related (or needs not be) to UInt32.

I started explaining this way, what I assumed you were asking about (I had to stare at this for a while after I realized it wasn’t your question):

It’s the U for Unsigned. It’s by design, while somewhat controversial, but can be justified.

Maybe helpful to see if you had evaluated a right-hand-side, and seen the cast to UInt32 fail:

```julia
julia> a::UInt32 = typemax(Int64)
ERROR: InexactError: trunc(UInt32, 9223372036854775807)

```
