Convert decimal to Gray code using binary reflected logic
Gray code, also known as reflected binary code, is a binary numeral system where two successive values differ in only one bit. This property prevents errors in digital communication, rotary encoders, and Karnaugh maps. The conversion uses XOR operation: G = B ^ (B >> 1).