Il giorno lunedì 19 ottobre 2015 08:56:32 UTC+2, Gunnar Farnebäck ha 
scritto:
>
> It might help if you explain something about what you want to do with the 
> binary representation.
>

I would like to have an efficient way to access bytes, 16 and 32 bit words 
of larger types (in this case 8 bytes, not necessarily floating point). 
Possibly as efficient and as easy as it could be in C/C++

    struct Words32 {

        int32_t lo;

        int32_t hi;

    };

    union Both {

        struct Words32 w;

        int64_t i;

    };

    union Both b;

    b.i=0x7fffffff3fffffff;

    printf("lo:0x%08x\nhi:0x%08x\n",b.w.lo,b.w.hi);

gives

*lo:0x3fffffff*

*hi:0x7fffffff*

*type Words32*

  *hi::Int32*

  *lo::Int32*

*end*

*a=0x7fffffff3fffffff*

*reinterpret(Words32,a)*


*gives*


*ERROR: reinterpret: expected bits type as first argument*

* in reinterpret at essentials.jl:115*


 

>
> For example,
>
> julia> f(x::Float64) = reinterpret(Float64, reinterpret(UInt64, x) & 
> 0x7fffffffffffffff)
> f (generic function with 1 method)
>


I have seen that I can reinterpret a bits type into another bits type of 
the SAME size. unfortunately my Words32 isn't, even if it size is 
completely specified and should be known ahead of time by the compiler. I'm 
looking for ways to access its smaller chunks without passing through a 
conversion into an hexadecimal string.

Reply via email to