You could write a function or macro to do this. Use a char array as the underlying type and abstract the bit access in the function/macro: Ex.: void SetBit( char *v, int n ) { v[n>>3] |=3D 1 << ( n & 7 ); } void ClrBit( char *v, int n ) { v[n>>3] &=3D ~( 1 << ( n & 7 )); } int ReadBit( char *v, int n ) { return ( v[n>>3] & ( 1 << ( n & 7 ))) ? 1 : 0; } Justin Richards escreveu: > was tagged [tech] > > 2009/7/21 Justin Richards > > = >> In C18 a union can be described as follows >> >> typedef union _IP_ADDR >> { >> BYTE v[4]; >> DWORD Val; >> } IP_ADDR; >> >> >> Then memory may be referenced as follows [after a variable IP of type >> IP_ADDR is declared] >> i=3D3; >> IP.v[i]; >> >> Can a similar member reference be used with bits. >> >> That is instead of referencing a bit member in the union below as >> >> iomask.bits.b0; >> >> Can it be referenced as >> >> iomask.bits[i]; or perhaps iomask.bits.b[i]; >> >> Experimenting with the compiler seems to indicate that it is not possibl= e. >> >> Pointers to examples etc would be greatly appreciated or even what to >> google for. >> >> union >> { >> struct >> { >> unsigned char b0:1; >> unsigned char b1:1; >> unsigned char b2:1; >> unsigned char b3:1; >> unsigned char b4:1; >> unsigned char b5:1; >> unsigned char b6:1; >> unsigned char b7:1; >> } bits; >> BYTE val; >> } iomask; >> >> Cheers Justin >> >> >> >> = >> ------------------------------------------------------------------------ >> >> >> Nenhum virus encontrado nessa mensagem recebida. >> Verificado por AVG - www.avgbrasil.com.br = >> Versao: 8.5.392 / Banco de dados de virus: 270.13.22/2253 - Data de Lanc= amento: 07/21/09 18:02:00 >> >> = __________________________________________________ Fa=E7a liga=E7=F5es para outros computadores com o novo Yahoo! Messenger = http://br.beta.messenger.yahoo.com/ = -- = http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist