converting floating point to RADIANCE HDR format

I have an array of M x N x 3 (as in RGB) single precision floating
point numbers,
and would like to save it as a RADIANCE hdr format which uses 32 bits
per pixel,
i.e. R G B have each 8 bits and they all share one exponent which is
also 8 bits.( If I understand this correctly)
I would like to know how exactly the format works. How does one pick
the common exponent? How does one deal with extrem intensity values in
the different color channels?
I am writing the program in C.
Can anyone help?