How do I convert a binary string to a floating point number?

Welcome back. The current version of Julia is 1.1, so go with that rather than 1.0.1. Julia today is not v0.6, its much cleaner and considerably more refined. At first glance it may look little different; as you write you’ll find good surprises that require reading the docs and looking for similar questions or asking here.

On converting a Float64 or Float32 into and backfrom a bitstring:
The first thing to note is that unlike Int64s and Int32s, floats have an exponent field and a significand field (and a sign bit). Ints are a signbit and all the rest of the bits behave more akin a significand than an exponent. So I’d suggest not using the exponent bits for genetic string elements – certainly not before having become comfortable with using the other float bits.

function float_from_bitstring(::Type{T}, str::String) where {T<:Base.IEEEFloat}
    unsignedbits = Meta.parse(string("0b", str))
    thefloat  = reinterpret(T, unsignedbits)
    return thefloat
end

julia> ϕ = (sqrt(5) + 1) / 2
1.618033988749895

julia> str = bitstring(ϕ)
"0011111111111001111000110111011110011011100101111111010010101000"

julia> float_from_bitstring(Float64, str)
1.618033988749895
6 Likes