This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

bit (and sbit) operation with == and != (bug?)

I have a problem that i cannot solve.

I need to compare two bit values.
Lets say:

bit Low = 0;
bit High = 1;

But I get some really strange results if I try to compare both of them:

Low == High will result in a 0
Low != High will also result in a 0 (expected 1)
High == Low will result in a 1
High != Low will also result in a 1 (expected 0)

(a compare with a constant like Low == 0 will work correctly)

It semms that I allways get the value of the first bit, but not the value of the comparison.
Same here with sbit operations.

But the C51 User Guide tells me:
~~~
The following operations may be executed with bit-type operands:
[...]
Compare bit with bit or constant (==, !=)
~~~

So whats the problem here ?

Parents
  • I tried this:

    main()
    {
    	bit	high = 1;
    	bit	low = 0;
    	bit	result = 0;
    
    	result = high == high;
    	result = high == low;
    	result = low == high;
    	result = low == low;
    
    	result = high != high;
    	result = high != low;
    	result = low != high;
    	result = low != low;
    }
    
    And I got exactly the results I expected.

    Can you post a sample of code that does not work?

Reply
  • I tried this:

    main()
    {
    	bit	high = 1;
    	bit	low = 0;
    	bit	result = 0;
    
    	result = high == high;
    	result = high == low;
    	result = low == high;
    	result = low == low;
    
    	result = high != high;
    	result = high != low;
    	result = low != high;
    	result = low != low;
    }
    
    And I got exactly the results I expected.

    Can you post a sample of code that does not work?

Children