Cool!  I think the extra step will be instructive anyways (that strings are not 
bits, and that bits have different interpretations depending on the type).




> On 17 Feb 2016, at 8:14 AM, Jacob Quinn <[email protected]> wrote:
> 
> There is the parse(type, str[, base]) function that will parse *integers* of 
> a given base (link to doc: 
> http://docs.julialang.org/en/release-0.4/stdlib/numbers/?highlight=binary#Base.parse
>  
> <http://docs.julialang.org/en/release-0.4/stdlib/numbers/?highlight=binary#Base.parse>),
>  but floats are always parsed as decimal. But using reinterpret, you could do
> 
> julia> str = bits(1.0f0)
> "00111111100000000000000000000000"
> 
> julia> int = parse(Int32,str,2)
> 1065353216
> 
> julia> reinterpret(Float32,int)
> 1.0f0
> 
> 
> -Jacob
> 
> On Tue, Feb 16, 2016 at 2:07 PM, Sheehan Olver <[email protected] 
> <mailto:[email protected]>> wrote:
> 
> 
> I'm lecturing a course that will include basic machine arithmetic, and the 
> bits function looks very helpful.  But is there a way to go back?  I.e., I 
> want a frombits to do:
> 
> 
> str=bits(1.0f0)    # returns "00111111100000000000000000000000"
> frombits(Float32,str)  # should return 1.0f0
> 
> 
> 

Reply via email to