32 bit Float to byte array (or 4 char string)
BlitzMax Forums/BlitzMax Programming/32 bit Float to byte array (or 4 char string)
| ||
I need to send floats through raknet messages and I suspect that I need to convert floats into 32-bit byte arrays and include the values as part of a message string to reconstruct the float on the other side. How would I go about doing such a converstion? (I don't know C++ but RakNet expects a struct to be sent which would handle floats, integers, and strings, etc - but searching this forum I gather this is nothing I can use in BlitzMax) |
| ||
Funny, after searching for a long time prior to writing this post I found a solution right after posting... how typical =) I found that I can use PokeFloat into a TBank and then convert the 4 bytes into chars for my string message - then I can peek the float on the other end. But are there any better solutions? |
| ||
Local f:Float '= blah Local arr:Byte[4] Float Ptr(arr)[0] = f Edit: Oh, or the string version: Local f:Float '= blah Local s:String = String.FromBytes(VarPtr f, 4) |
| ||
Oh :) It was that simple? =) haha, thanks - I should have asked a lot sooner! |
| ||
convert floats into 32-bit byte arrays and include the values as part of a message string Is this a C-style null terminated string? If so then that won't be reliable. |