<?php




function gray_encode($binary){
	return $binary ^ ($binary >> 1);
}


function gray_decode($gray){
	$binary = $gray;
	while($gray >>= 1) $binary ^= $gray;
	return $binary;
}

for($i=0;$i<32;$i++){
	$gray_encoded = gray_encode($i);
	printf(,$i, $i, $gray_encoded, $gray_encoded, gray_decode($gray_encoded));
}