Re: How to convert byte array to float

2015-07-17 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, July 17, 2015 18:43:26 DLangLearner via Digitalmars-d-learn wrote: > Excuse me for my trivial question, but I'd like to know how to > convert byte array to float? What I could think of are > cast(float)(byte[]) and to!float(byte[]) but they do not work for > me. Thanks! You could use st

Re: How to convert byte array to float

2015-07-17 Thread DLangLearner via Digitalmars-d-learn
On Friday, 17 July 2015 at 18:58:33 UTC, byron wrote: On Friday, 17 July 2015 at 18:53:24 UTC, byron wrote: On Friday, 17 July 2015 at 18:43:27 UTC, DLangLearner wrote: Excuse me for my trivial question, but I'd like to know how to convert byte array to float? What I could think of are cast(fl

Re: How to convert byte array to float

2015-07-17 Thread byron via Digitalmars-d-learn
On Friday, 17 July 2015 at 19:03:46 UTC, Jacob Carlborg wrote: 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 wel

Re: How to convert byte array to float

2015-07-17 Thread Jacob Carlborg via Digitalmars-d-learn
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

Re: How to convert byte array to float

2015-07-17 Thread byron via Digitalmars-d-learn
On Friday, 17 July 2015 at 18:53:24 UTC, byron wrote: On Friday, 17 July 2015 at 18:43:27 UTC, DLangLearner wrote: Excuse me for my trivial question, but I'd like to know how to convert byte array to float? What I could think of are cast(float)(byte[]) and to!float(byte[]) but they do not work

Re: How to convert byte array to float

2015-07-17 Thread byron via Digitalmars-d-learn
On Friday, 17 July 2015 at 18:43:27 UTC, DLangLearner wrote: Excuse me for my trivial question, but I'd like to know how to convert byte array to float? What I could think of are cast(float)(byte[]) and to!float(byte[]) but they do not work for me. Thanks! You want to include [] in the cast s