0

I got stuck in solving the problem as shown below

Suppose I have two Variable A=10010101 [Correct Bit Value] & B=11001010 [Error Bit value which needs to be compared with A]

The above two variables are eight bit, I need to compare the value at each position from most significant bit to the last bit. What I need is to print the position where they are not identical and what should be the correct/error value for that position.

Example: For B, second position bit value should be '0' when we compared to bit value at position 2nd for A.

I tried to use XOR operation but in that case i didn't find the correct value at that position. Also i want to let you know that Bit A value is fixed and bit B value comes dynamically form a device.

Thanks for your valuable time.

Mike
  • 17
  • 6
  • This lacks code, it's very much a "please write this for me" question. – unwind Dec 19 '16 at 11:46
  • @unwind sir no need to write if you can just help me with the logic.As I'm unable to code it of my own without proper logic. Thanks for review – Mike Dec 19 '16 at 12:06

2 Answers2

0

If I get you right, your logic should be like this:

ForEach elem in A 
    C[elem.index] = A XOR B

ForEach elem in C
    if elem == 1 
        print elem.index
Raskayu
  • 735
  • 7
  • 20
0

Just compare bits and if they are different, print the index and corresponding bit from A.

for(i=0 to sizeof(A))
{
    tempA = A & (1 << i); //Get ith bit of A
    tempB = B & (1 << i); //Get ith bit of B
    if(tempA != tempB ) //Check if they are same.
        printf(i, tempA); //If they are different, print position and correct value.
}
MayurK
  • 1,925
  • 14
  • 27
  • Thanks sir for logic I'll code it and give u my feedback – Mike Dec 19 '16 at 12:59
  • If you do A XOR B you get an integer that only has bits set that are different in A and B. Then you can [search for highest bit set](http://stackoverflow.com/questions/671815/what-is-the-fastest-most-efficient-way-to-find-the-highest-set-bit-msb-in-an-i). – Gerhardh Dec 19 '16 at 14:32
  • @Gerhardh: You are right. But I was just trying to explain the logic with some pseudo code. Also please note, you need to print all bits where error is occured, not just the highest bit. – MayurK Dec 19 '16 at 16:27