Converting float to byte[] - BitConverter?

Hi

Since I can’t use XML or Serializer in the Unity iPhone Basic License I am about to build a file format of my own which I can parse in the iPhone, I think converting my data to a byte array would be the best, I have managed to convert int’s and booleans to bytes but I can’t figure out how to convert a float to a byte array.
Does anyone know how to do it?

I have seen the BitConverter class on the internet but I don’t know if I can use it since the basic license does not allow using the System namespace.

Thanks,
Aron

You can sometimes encode a real number (ie, float) in an integer, depending on what range and accuracy you need. For example, you could multiply the original float by 10000 and cast to integer (losing the fractional part). To decode it again, you just cast the integer to float and divide it by 10000 again. It’s a slight nuisance and your requirements for range and accuracy of the numbers may not allow it at all. However, it can be a handy technique if nothing else is available.

1 Like

Thanks Andeeee!!