Converting integer to string in Julia

You should use:

b = string(a)

or

b = repr(a)

string function can be used to create string from any value using print and repr uses showall. In case of Int64 this is equivalent.

And actually this is probably the reason why convert does not work – as there are many ways to convert integer to string depending on the choice of base.

EDIT

For integers you could convert them in the past version of Julia to string also using bin, dec, hex, oct or base.

Past Julia 1.0 you can do the conversions in different bases using string function with base keyword argument for integers. Also you have bitstring function that gives the literal bit representation of a number. Here are some examples:

julia> string(100)
"100"

julia> string(100, base=16)
"64"

julia> string(100, base=2)
"1100100"

julia> bitstring(100)
"0000000000000000000000000000000000000000000000000000000001100100"

julia> bitstring(UInt8(100))
"01100100"

julia> string(100.0)
"100.0"

julia> string(100.0, base=2)
ERROR: MethodError: no method matching string(::Float64; base=2)
Closest candidates are:
  string(::Any...) at strings/io.jl:156 got unsupported keyword argument "base"
  string(::String) at strings/substring.jl:146 got unsupported keyword argument "base"
  string(::SubString{String}) at strings/substring.jl:147 got unsupported keyword argument "base"
  ...
Stacktrace:
 [1] top-level scope at none:0

julia> bitstring(100.0)
"0100000001011001000000000000000000000000000000000000000000000000"

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)