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

BUG with bits in integer variable

There is a BUG in the compilation of a bit definition:

unsigned int bdata my_int;
sbit bit15 = my_int ^ 15;
sbit bit7 = my_int ^ 7;

void main()
{
  my_int = 0x8000;

  if(bit15)
  {
    // Here we shall not appear,as compiller
    // will be erroneous to check 7-bit of
    // a variable my_int instead of 15-bit
    // (as this variable place in memory in
    // little endian order)
    // ...
  }

  if(bit7)
  {
    // oops! we here!
    // ...
  }
}
This is a BUG! Please correct. Thanx.

Parents
  • This is why there are also two ways people like to number bits (bit endianness) as well as bytes (byte endianness). Whichever method you pick, someone will be unhappy.

    Intel ordained the hardware's method of number bits and mapping bit addresses to bytes.

    Either the multi-byte sbit type has non-continguous bits when numbered sequentially, the bit numbers don't match order of physical bit addresses, or the sbit bit numbers won't match the number of shifts needed with the shift operators to get to that bit position.

Reply
  • This is why there are also two ways people like to number bits (bit endianness) as well as bytes (byte endianness). Whichever method you pick, someone will be unhappy.

    Intel ordained the hardware's method of number bits and mapping bit addresses to bytes.

    Either the multi-byte sbit type has non-continguous bits when numbered sequentially, the bit numbers don't match order of physical bit addresses, or the sbit bit numbers won't match the number of shifts needed with the shift operators to get to that bit position.

Children