Assume that
- Background is black.
- The A channel is linear (0-255), so 0=black (background) and 255=foreground
- The grayscale is linear (0-255), so 0=black and 255=white
Then gray 35 at opacity 255 is the same as gray 52 at opacity 255*35/52 = 171.
But all these assumptions are dubious. In games programming using float values for colours and transparency and with control over the gamma curve this is all much easier. In CSS, not so much.