Generating N | Function to Generating N - bit Gray Code starting from K ; Generate gray code of corresponding binary number of integer i . ; Driver code
function genSequence ( n , val ) { for ( let i = 0 ; i < ( 1 << n ) ; i ++ ) { let x = i ^ ( i >> 1 ) ^ val ; document . write ( x + " " ) ; } } let n = 3 , k = 2 ; genSequence ( n , k ) ;