How to read a Bit from a Byte ?

Respectable colleagues,

how to read a value of a BIT from value of a BYTE variable in Keil C ?

For example:
X=(Byte1.Bit7*4)+(Byte1.Bit6*2)

Thanks in advance.

With best regards,

Dragan Kujovic

Parents
  • In C51, you'd have to go via a bit-addressable object; ie,

    1. Copy your byte to a bit-addressable byte
    2. Access the required bit
    3. If required, write back to your original byte.

    Beware the optimiser!

    Failing that, the normal 'C' tools of masks/shifts, or bitfields - taking care to read the manual & app notes on bit & byte ordering.

Reply
  • In C51, you'd have to go via a bit-addressable object; ie,

    1. Copy your byte to a bit-addressable byte
    2. Access the required bit
    3. If required, write back to your original byte.

    Beware the optimiser!

    Failing that, the normal 'C' tools of masks/shifts, or bitfields - taking care to read the manual & app notes on bit & byte ordering.

Children
More questions in this forum