Mail Archives: djgpp/1998/04/15/13:16:40
Hi!
You must use bit fields, a struct, and a union (see my example below).
Hope this helps.
Trond Endrestøl.
------------------------------------------------------------------
#include <iostream.h>
typedef struct bits_in_a_byte {
int Bit01 : 1;
int Bit02 : 1;
int Bit03 : 1;
int Bit04 : 1;
int Bit05 : 1;
int Bit06 : 1;
int Bit07 : 1;
int Bit08 : 1;
} bits_in_a_byte;
typedef unsigned char byte;
typedef union byte_and_bits {
byte Byte;
bits_in_a_byte Bits;
} byte_and_bits;
int main()
{
byte_and_bits MyByte;
MyByte.Byte = 55;
cout << (unsigned int)MyByte.Byte << endl; // Should display 55
MyByte.Bits.Bit08 = 1;
cout << (unsigned int)MyByte.Byte << endl; // Should display 183
return 0;
}
______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com
- Raw text -