PDA

View Full Version : bytes and floats



jono_123
09-07-2002, 01:53 AM
in my opengl programs i want to convert 3 bytes to a float: i have 3 bytes x,y,and z. x*256*256 + y*256 + z = some_number
how do i find the 3 bytes if i know some_number? thanx very much http://www.opengl.org/discussion_boards/ubb/smile.gif

MickeyMouse
09-07-2002, 02:15 AM
that's really not OpenGL related http://www.opengl.org/discussion_boards/ubb/frown.gif
anyway, here's the solution http://www.opengl.org/discussion_boards/ubb/biggrin.gif :

int n = (int) some_number;
int x = n >> (8 + 8);

n = n - (n >> (8 + 8));
int y = n >> 8;

n = n - (n >> 8);
int z = n;

I believe you needn't have posted it here http://www.opengl.org/discussion_boards/ubb/wink.gif

[This message has been edited by MickeyMouse (edited 09-07-2002).]