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

Hi,

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

Any help welcome !

Use 0.7 to see what happened to them.

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"
2 Likes

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

3 Likes

Thanks everyone.

Had no warnings with the x86_64 1.0.1 binary btw:

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…

Deprecation warnings are in 0.7.

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

In 0.6:

julia> typeof(hex(12))
String

In 1.0:

julia> typeof(string(12; base=16))
String
@deprecate hex(n)          string(n, base = 16)

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.

You can simply define your own:

hex(n)=string(n, base=16)
2 Likes

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.

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

1 Like

Language could be simple as Brainfuck but that does not mean simplicity in coding.

Let me show you why you’re wrong:

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

I don’t need an effort here.

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

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)
4 Likes