# Base conversion (hex, bin, octal...)

**URL:** <https://discourse.julialang.org/t/base-conversion-hex-bin-octal/15969>\
**Category:** General Usage\
**Created:** [October 6, 2018, 5:23pm UTC](https://discourse.julialang.org/t/base-conversion-hex-bin-octal/15969 "2018-10-06T17:23:23Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![JuliaCaesar](https://avatars.discourse-cdn.com/v4/letter/j/ac8455/32.png) [@JuliaCaesar](https://discourse.julialang.org/u/JuliaCaesar)\
**Post date:** [October 6, 2018, 5:23pm UTC](https://discourse.julialang.org/t/base-conversion-hex-bin-octal/15969/1 "2018-10-06T17:23:23Z")

</div>

Hi,

seems that some functions vanished in the 1.x release.  
Can’t find something on the docs.

Any help welcome !

---

<div class="post-metadata">

**Author:** ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)\
**Post date:** [October 6, 2018, 5:26pm UTC](https://discourse.julialang.org/t/base-conversion-hex-bin-octal/15969/2 "2018-10-06T17:26:15Z")

</div>

Use 0.7 to see what happened to them.

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [October 6, 2018, 5:26pm UTC](https://discourse.julialang.org/t/base-conversion-hex-bin-octal/15969/3 "2018-10-06T17:26:23Z")

</div>

```julia
julia> hex(123)
┌ Warning: `hex(n)` is deprecated, use `string(n, base=16)` instead.
│ caller = top-level scope at none:0
└ @ Core none:0
"7b"

```

---

<div class="post-metadata">

**Author:** ![jandehaan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jandehaan/32/6805_2.png) [@jandehaan](https://discourse.julialang.org/u/jandehaan)\
**Post date:** [October 7, 2018, 12:20am UTC](https://discourse.julialang.org/t/base-conversion-hex-bin-octal/15969/4 "2018-10-07T00:20:33Z")

</div>

If you expected a Julia Base function to work in Julia 1.0 but it doesn’t, and you don’t have a Julia 0.7 environment to verify if that particular function has been deprecated, look in  
[https://github.com/JuliaLang/julia/blob/release-0.7/base/deprecated.jl](https://github.com/JuliaLang/julia/blob/release-0.7/base/deprecated.jl)

---

<div class="post-metadata">

**Author:** ![JuliaCaesar](https://avatars.discourse-cdn.com/v4/letter/j/ac8455/32.png) [@JuliaCaesar](https://discourse.julialang.org/u/JuliaCaesar)\
**Post date:** [October 8, 2018, 2:04pm UTC](https://discourse.julialang.org/t/base-conversion-hex-bin-octal/15969/5 "2018-10-08T14:04:29Z")

</div>

Thanks everyone.

Had no warnings with the x86\_64 1.0.1 binary btw:

```julia
julia> hex(12)
ERROR: UndefVarError: hex not defined
Stacktrace:
 [1] top-level scope at none:0

```

It’s strange to get a string with the new function…

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [October 8, 2018, 2:07pm UTC](https://discourse.julialang.org/t/base-conversion-hex-bin-octal/15969/6 "2018-10-08T14:07:50Z")

</div>

> [@JuliaCaesar](#):
>
> Had no warnings with the x86\_64 1.0.1 binary btw:

Deprecation warnings are in 0.7.

> [@JuliaCaesar](#):
>
> It’s strange to get a string with the new function…

Hm, you mean it is strange to get a string with `string`?

---

<div class="post-metadata">

**Author:** ![kdyrhage](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kdyrhage/32/2326_2.png) [@kdyrhage](https://discourse.julialang.org/u/kdyrhage)\
**Post date:** [October 8, 2018, 2:10pm UTC](https://discourse.julialang.org/t/base-conversion-hex-bin-octal/15969/7 "2018-10-08T14:10:25Z")

</div>

> [@JuliaCaesar](#):
>
> It’s strange to get a string with the new function…

In 0.6:

```julia
julia> typeof(hex(12))
String

```

---

<div class="post-metadata">

**Author:** ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)\
**Post date:** [October 8, 2018, 2:15pm UTC](https://discourse.julialang.org/t/base-conversion-hex-bin-octal/15969/8 "2018-10-08T14:15:11Z")

</div>

> [@kdyrhage](#):
>
> > It’s strange to get a string with the new function…
> 
> In 0.6:
> 
> ```julia
> julia> typeof(hex(12))
> String
> 
> ```

In 1.0:

```julia
julia> typeof(string(12; base=16))
String

```

---

<div class="post-metadata">

**Author:** ![jandehaan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jandehaan/32/6805_2.png) [@jandehaan](https://discourse.julialang.org/u/jandehaan)\
**Post date:** [October 8, 2018, 2:34pm UTC](https://discourse.julialang.org/t/base-conversion-hex-bin-octal/15969/9 "2018-10-08T14:34:38Z")

</div>

```julia
@deprecate hex(n) string(n, base = 16)

```

---

<div class="post-metadata">

**Author:** ![JuliaCaesar](https://avatars.discourse-cdn.com/v4/letter/j/ac8455/32.png) [@JuliaCaesar](https://discourse.julialang.org/u/JuliaCaesar)\
**Post date:** [October 9, 2018, 6:48am UTC](https://discourse.julialang.org/t/base-conversion-hex-bin-octal/15969/10 "2018-10-09T06:48:39Z")

</div>

Ok, thought bases were treated as numbers.

Anyway, the new syntax is not convenient for quick base conversions, hope the bin() hex() oct() will be added back.

---

<div class="post-metadata">

**Author:** ![davide](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/davide/32/52136_2.png) [@davide](https://discourse.julialang.org/u/davide)\
**Post date:** [October 9, 2018, 6:56am UTC](https://discourse.julialang.org/t/base-conversion-hex-bin-octal/15969/11 "2018-10-09T06:56:45Z")

</div>

You can simply define your own:

```julia
hex(n)=string(n, base=16)

```

---

<div class="post-metadata">

**Author:** ![JuliaCaesar](https://avatars.discourse-cdn.com/v4/letter/j/ac8455/32.png) [@JuliaCaesar](https://discourse.julialang.org/u/JuliaCaesar)\
**Post date:** [October 10, 2018, 12:30pm UTC](https://discourse.julialang.org/t/base-conversion-hex-bin-octal/15969/12 "2018-10-10T12:30:01Z")

</div>

Of course, but the simplicity is gone away.  
I mean Julia is supposed to be simple, that’s what I like about it.  
In this case it’s bad, it’s like a microsoft-ization.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [October 10, 2018, 1:00pm UTC](https://discourse.julialang.org/t/base-conversion-hex-bin-octal/15969/13 "2018-10-10T13:00:03Z")

</div>

> [@JuliaCaesar](#):
>
> Of course, but the simplicity is gone away.

I think that reducing the number of functions while retaining functionality actually made the language simpler.

---

<div class="post-metadata">

**Author:** ![Liso](https://avatars.discourse-cdn.com/v4/letter/l/898d66/32.png) [@Liso](https://discourse.julialang.org/u/Liso)\
**Post date:** [October 10, 2018, 6:36pm UTC](https://discourse.julialang.org/t/base-conversion-hex-bin-octal/15969/14 "2018-10-10T18:36:24Z")

</div>

> [@Tamas\_Papp](#):
>
> > [@JuliaCaesar](#):
> >
> > Of course, but the simplicity is gone away.
> 
> I think that reducing the number of functions while retaining functionality actually made the language simpler.

Language could be simple as [Brainfuck](https://en.wikipedia.org/wiki/Brainfuck) but that does not mean simplicity in coding.

---

<div class="post-metadata">

**Author:** ![JuliaCaesar](https://avatars.discourse-cdn.com/v4/letter/j/ac8455/32.png) [@JuliaCaesar](https://discourse.julialang.org/u/JuliaCaesar)\
**Post date:** [October 11, 2018, 6:02am UTC](https://discourse.julialang.org/t/base-conversion-hex-bin-octal/15969/15 "2018-10-11T06:02:57Z")

</div>

Let me show you why you’re wrong:

```julia
$ python
>>> hex(32)
'0x20'
>>> bin(44)
'0b101100'
>>> oct(24)
'030'

```

I don’t need an effort here.

---

<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:** [October 11, 2018, 8:29am UTC](https://discourse.julialang.org/t/base-conversion-hex-bin-octal/15969/16 "2018-10-11T08:29:21Z")

</div>

True. But on the other hand, you can do this:

```julia
julia-1.0> hex = "Petrificus Totalus"
"Petrificus Totalus"

julia-1.0> bin = 0b100100100
0x0124

julia-1.0> dec(f) = f-1
dec (generic function with 1 method)

```
