Tricky casting/encoding problem
Monkey Forums/Monkey Programming/Tricky casting/encoding problem
| ||
Hi! I want to encode a 32-bit float (particularly and angle. I suppose it can be 16-bit as well) in as few characters as possible. The easiest way I came up with was to actually interpret the data as an unsigned int. In C++ this would be pretty easy: float f = 3723.1187291f; int* a = (int*)&f; int b = (*a); However in monkey this is proving quite difficult. Since monkey doesn't have pointers, I thought maybe I could write the float to a stream then read an int, however no streams :) I'm running out of ideas. Basically I just want to encode that angle into a code that the user can input. Any ideas? |
| ||
You could do the conversion by yourself: http://sandbox.mc.edu/~bennet/cs110/flt/dtof.html But this might not be that fast actually. Or you just do the native part where pointers are possible - this won't work for all platforms then of course. |