bit access folowup
Posted: Thu Oct 18, 2007 8:29 am
as a follow up on the bit access topic, i finally finished my basic types int8, int16, int32, int64, int128 and the unsigned counterparts. Each of these types have bit access in the form variable(firstbit, sizeinbits). The following program shows its use:
As one can see it is possible to assign bits to values, values to bits and bits to bits. The outcome of this example is: (with the values being calculated on compile time)
Code: Select all
void main(void)
{ //- initialise vga memory (128 KiB).
Region<uint64>(0xA0000, 0xC0000) = uint64(0x1720172017201720);
uint8 byte(-1); //- byte = 0xFF
uint8 data = byte(2,4); //- data = 0x0F
cout << "data: $" << data << "\n";
byte(2,4) = ~data; //- byte = 0xC3
cout << "byte: $" << byte << "\n";
data(4,4) = byte(0,4); //- data = 0x3F
cout << "data: $" << data << "\n";
cout << "data: $" << data(1,6) << "\n";
cout << "\ndone...";
}
I still need to comment the code but will put it on my website when done.data: $0F
byte: $C3
data: $3F
data: $1F