for two 's complement go from right to left in  ones complement and if we get 1 make, we make  them 0 and keep going left when we get first  0, make that 1 and go out of loop
twos = ones ; twos = twos . split ( ' ' ) for ( i = n - 1 ; i >= 0 ; i -- ) { if ( ones [ i ] == ' ' ) twos [ i ] = ' ' ; else { twos [ i ] = ' ' ; break ; } } twos = twos . join ( ' ' )