Is it possible to save pixel perfect full-spectrum rgb height map?
Your calculation looks incorrect. Also, are you expecting RGB values in the range 0-255 or in the range 0.0-1.0? Blender shader nodes expect values in the range 0.0 -&gt; 1.0.
I suspect you actually require something like the folllowing :
B = C % 256
G = ( (C - B) / 256 ) % 256
R = ( ( (C - B) / 256 - G ) / 256 )

This will produce a colour with each channel in the range 0-255
Then, produce a shader colour (ranged 0.0-1.0) using :
Color = (R/255 , G/255, B/255)