Click here to Skip to main content
15,889,992 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
in this piece of code bit masking technique and XOR operation are used, could you please explain me about these techniques and what's the alternative ways instead of these methods?

What I have tried:

some techniques in C++
Posted
Updated 28-Apr-18 12:19pm
v2

Quote:
for (i = 1; i <= n; i++){
if (i == pow(2, p)){ Final[i] = 0;
p++;}
else{
Final[i] = b[j];
j++;
}}

No XOR used in the above piece of code.

You should understand we (or, at least I) have no idea about the purpose of such (incomplete) code.
 
Share this answer
 
Without context, your code is meaningless, we have no way to know what is going on because it depend on other piece of code that we don't know.
When you post a piece of code, it is a good idea to post an autonomous piece of code (code that we can compile and run)(this include the data).
-----
Learn to indent properly your code, it show its structure and it helps reading and understanding. It also helps spotting structures mistakes.
C++
for (i = 1; i <= n; i++){
  if (i == pow(2, p)){
    Final[i] = 0;
    p++;
  }
  else{
    Final[i] = b[j];
    j++;
  }
}

C++
for (i = 1; i < pow(2, r); i = pow(2, x)){
  for (j = 1; j <= n; j++){
    if ((i&j) == i)
      Final[i] ^= Final[j];
  }
  x++;
  std::cout << std::endl << i <<" " <<Final[i] ;
}


Professional programmer's editors have this feature and others ones such as parenthesis matching and syntax highlighting.
Notepad++ Home[^]
ultraedit[^]
 
Share this answer
 
Comments
Rick York 30-Mar-18 0:28am    
I agree. Proper indentation can help a lot. However, I do not consider either of your snippets to be examples of proper indentation. As far as I am concerned, your examples are no better than his. Of course, opinions vary.
Patrice T 30-Mar-18 2:07am    
Hi Rick,
My examples are simply OP pieces of code with minimum changes to get correct indentation with respect to OP coding style as much as possible.
What would you consider proper indentation for this code ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900