How to convert byte array to float

Jonathan M Davis via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Jul 17 12:34:02 PDT 2015


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 std.bitmanip.peek or std.bitmanip.read - though you do need to
make sure that you're telling it the right endianness, depending on how the
array of bytes was generated.

- Jonathan M Davis



More information about the Digitalmars-d-learn mailing list