4
happens to be 8 / 2
[citation needed], or CHAR_BIT / 2
.
Your gray code decoding algorithm start by taking the left half of the given integer type, and shifts it to the right half of the type, which happens to be sizeof(type) * (CHAR_BIT / 2)
bits to the right, which is exactly what you are seeing.
As pointed out in the comments, std::numeric_limits<type>::digits / 2
would be the more idiomatic solution for C++.