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


#1

Hi,

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

Any help welcome !


#2

Use 0.7 to see what happened to them.


#3
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"

#4

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


#5

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…


#6

Deprecation warnings are in 0.7.

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


#7

In 0.6:

julia> typeof(hex(12))
String

#8

In 1.0:

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

#9
@deprecate hex(n)          string(n, base = 16)

#10

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.


#11

You can simply define your own:

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

#12

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.


#13

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


#14

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


#15

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.


#16

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)