algorithm - The use of XOR for removing character from string and finding duplicates -


the following questions based on use of xor :

  1. given string of integers. task @ hand remove given character string. tried using xor solve it. eg char str[] = "123456" . remove 4. xor given character entire string. character vanishes.

    xor = (1^2^3^4^5^6) ^ 4 

    however left xor of remaining characters.

    xor = (1^2^3^5^6) 

    is there method individual characters back?

  2. i need find , remove elements have duplicates (including elements themselves)

    eg. = {1,9,8,2,2} output should {1,9,8} after removal

    however fail since 1^9 = 8. hence (1^9)^8^2^2 gives empty array. there alternative using xor itself?

int num=4; for(i=0;i<strlen(str);i++) {     if(((str[i]-'0')^num) == 0)         remove_number(i); } 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -