| Author | beginning argument ( Replies received: 5 ) |
| Spectre |
Posted 06-10-2008 at 10:16   |

Registered on : 11-06-2005
From Italy
Messages : 147
OFF-Line
|
Dear forum members,
I have a c newbye question.I need to create a bit array instead of a byte array but I don't know the way.
Can you help me ?
thanks
Spectre
|
|
|
Profile
Quote
|
| Spectre |
Posted 06-10-2008 at 10:17   |

Registered on : 11-06-2005
From Italy
Messages : 147
OFF-Line
|
|
Profile
Quote
|
| _luca |
Posted 07-10-2008 at 09:28   |

Registered on : 01-21-2004
From France
Messages : 199
OFF-Line
|
Ciao Enrico,
sorry but this is not possible: see the manual, page 41.
Regards,
Luca (Cosmic)
|
|
|
Profile
Quote
|
| woro |
Posted 08-10-2008 at 12:06   |

Registered on : 07-17-2003
From Germany
Messages : 189
OFF-Line
|
Hi Spectre,
although I think that you know the workarounds for this special problem I'll recall two of them here.
1st: creating (or make use of) macros as
#define SetBit(VAR,Place) (VAR |= (1'<<'Place))
#define ClrBit(VAR,Place) (VAR &= ((1'<<'Place)^255))
#define ChgBit(VAR,Place) (VAR ^= (1'<<'Place))
#define AffBit(VAR,Place,Val) ((Val) ? (VAR |= (1'<<'Place)):(VAR &= ((1'<<'Place)^255)))
#define ValBit(VAR,Place) ((VAR & (1'<<'Place)) != 0)
(!!!! as it isn't possible to use the [shift left] Symbol in this message I took 1'<<'place. You may remove the '-signs (apostrophes) to use the code !!!)
2nd (as I prefere in the majority of cases): creating bit-structures
struct {
unsigned int bit0 :1;
unsigned int bit1 :1;
unsigned int bit2 :1;
...
} bit_array;
where you can use the single bits as part of the structure
- if(bit_array.bit1 == 1) ...
- bit_array.bit1 = 1;
- bit_array.bit2 ^= 1;
- bit_array.bit0 = bit_array.bit1;
etc.
Regards,
WoRo
|
|
|
Profile
Quote
|
| woro |
Posted 08-10-2008 at 12:07   |

Registered on : 07-17-2003
From Germany
Messages : 189
OFF-Line
|
Hi Spectre,
although I think that you know the workarounds for this special problem I'll recall two of them here.
1st: creating (or make use of) macros as
#define SetBit(VAR,Place) (VAR |= (1'<<'Place))
#define ClrBit(VAR,Place) (VAR &= ((1'<<'Place)^255))
#define ChgBit(VAR,Place) (VAR ^= (1'<<'Place))
#define AffBit(VAR,Place,Val) ((Val) ? (VAR |= (1'<<'Place)):(VAR &= ((1'<<'Place)^255)))
#define ValBit(VAR,Place) ((VAR & (1'<<'Place)) != 0)
(!!!! as it isn't possible to use the [shift left] Symbol in this message I took 1'<<'place. You may remove the '-signs (apostrophes) to use the code !!!)
2nd (as I prefere in the majority of cases): creating bit-structures
struct {
unsigned int bit0 :1;
unsigned int bit1 :1;
unsigned int bit2 :1;
...
} bit_array;
where you can use the single bits as part of the structure
- if(bit_array.bit1 == 1) ...
- bit_array.bit1 = 1;
- bit_array.bit2 ^= 1;
- bit_array.bit0 = bit_array.bit1;
etc.
Regards,
WoRo
|
|
|
Profile
Quote
|
| Spectre |
Posted 20-10-2008 at 08:48   |

Registered on : 11-06-2005
From Italy
Messages : 147
OFF-Line
|
thanks woro!
have a nice day
|
|
|
Profile
Quote
|