# Julia C constant equivalent

**URL:** https://discourse.julialang.org/t/julia-c-constant-equivalent/62144
**Category:** New to Julia
**Created:** [May 31, 2021, 4:17pm UTC](https://discourse.julialang.org/t/julia-c-constant-equivalent/62144 "2021-05-31T16:17:51Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![gitboy16](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gitboy16/32/24906_2.png) [@gitboy16](https://discourse.julialang.org/u/gitboy16)
#### Post date: [May 31, 2021, 4:17pm UTC](https://discourse.julialang.org/t/julia-c-constant-equivalent/62144/1 "2021-05-31T16:17:51Z")

</div>

Hi,

What is the equivalent in Julia of 0x8000000000000000ull which is sometimes used in C?

Example in C someone could write :

```julia
(x >> 63) | 0x8000000000000000ull

```

Assuming `uint64_t x`.

Thank you

---

<div class="post-metadata">

### Author: ![Gnimuc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gnimuc/32/2194_2.png) [@Gnimuc](https://discourse.julialang.org/u/Gnimuc)
#### Post date: [May 31, 2021, 4:21pm UTC](https://discourse.julialang.org/t/julia-c-constant-equivalent/62144/2 "2021-05-31T16:21:39Z")

</div>

You need to use `Culonglong(0x8000000000000000)`.

---

<div class="post-metadata">

### Author: ![sijo](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@sijo](https://discourse.julialang.org/u/sijo)
#### Post date: [May 31, 2021, 4:26pm UTC](https://discourse.julialang.org/t/julia-c-constant-equivalent/62144/3 "2021-05-31T16:26:52Z")

</div>

I’m not sure anything particular is required for such cases? For example:

```julia
julia> x = typemax(UInt64)
0xffffffffffffffff

julia> (x >> 63) | 0x8000000000000000
0x8000000000000001

```

In Julia integer literal are automatically given a “big enough” type, at least up to 128-bit. So `0x8000000000000000` is a UInt64. You can request a specific type by writing e.g. `UInt128(0x8000000000000000)`. But you get `UInt128` automatically if you write a larger literal integer:

```julia
julia> typeof(0x1000000000000000000000000000000)
UInt128

```

---

<div class="post-metadata">

### Author: ![gitboy16](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gitboy16/32/24906_2.png) [@gitboy16](https://discourse.julialang.org/u/gitboy16)
#### Post date: [May 31, 2021, 4:35pm UTC](https://discourse.julialang.org/t/julia-c-constant-equivalent/62144/4 "2021-05-31T16:35:31Z")

</div>

I am confused now 🙂 So which one is the correct answer:

```julia
Culonglong(0x8000000000000000)
0x8000000000000000
Or
UInt64(0x8000000000000000)

```

It seems they all work

---

<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: [May 31, 2021, 4:40pm UTC](https://discourse.julialang.org/t/julia-c-constant-equivalent/62144/5 "2021-05-31T16:40:15Z")

</div>

> [@gitboy16](#):
>
> So which one is the correct answer:

The shortest correct answer, assuming you want `UInt64`, is simply `0x8000000000000000`.

As @sijo explained, the type of an integer literal `0x....` in Julia is determined by the number of digits, so there is no need for suffixes. For example, `0x80` is a `UInt8`, `0x8000` is `UInt16`, and `0x80000000` is a `UInt32`.

(If you need a C `unsigned long long` specifically, you might want to cast it to `Culonglong` explicitly in case `Culonglong` is different from a `UInt64`, but I’m not aware of any supported platform where this is the case. Moreover, the values are converted on assignment anyway, e.g. if you have a `ccall` with a `Culonglong` argument or a `struct` with a `Culonglong` field to mirror a C type then you can just pass/assign a `UInt64` and it will get converted if needed.)
