Well, to convert them back, you would do the colors in reverse, like this:
fiveBitR = eightBitR * (31/255)
hmmm I'm not sure you understand the problem you are creating by doing it this way let me explain (knowing a fair amount about compilors).
if you want to use only integer math this is much better
(R8 * 31)/255
, this results in taking the integer multiplying it by 31 then deviding the result by 255. Otherwise the compilor will do this instead, 31/255 result is < 1, thus it will create the floating point constant of 31/255. Then it will convert your R8 value to floating point (at runtime) multiply it by the 31/255 constant and convert the result back to an integer and store that integer as the result. The difference is this has quite a few more operations involved and also involves 3 floating point operations. If he wants to do it fast, it's definately not the fast way to do it.
Of course we could then discuse doing this using mmx instructions which is much faster, however It's not really that important to go on and on about how to make the code faster.
This is so you know that you need to consider what it is you are doing carefully, if you don't wish to have unintended consequences in your code.
Cyb