How to convert byte array to float

Jacob Carlborg via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Jul 17 12:03:34 PDT 2015


On 2015-07-17 20:58, byron wrote:

> Ah I miss read, if you want as a float, not a float array you can do:
>
> byte[] b = [1, 2, 3, 4];
> float f = *cast(float*)b.ptr;
>
> not sure if there is a better way

I think a union can be used as well, not sure if it's better though.

-- 
/Jacob Carlborg


More information about the Digitalmars-d-learn mailing list