Toggle all the bits of a number except k | Returns a number with all bit toggled in n except k - th bit ; 1 ) Toggle k - th bit by doing n ^ ( 1 << k ) 2 ) Toggle all bits of the modified number ; Driver code
function toggleAllExceptK ( n , k ) { return ~ ( n ^ ( 1 << k ) ) ; } let n = 4294967295 ; let k = 0 ; document . write ( toggleAllExceptK ( n , k ) ) ;