bit access folowup

Programming, for all ages and all languages.
Post Reply
User avatar
os64dev
Member
Member
Posts: 553
Joined: Sat Jan 27, 2007 3:21 pm
Location: Best, Netherlands

bit access folowup

Post by os64dev »

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:

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...";
}
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)
data: $0F
byte: $C3
data: $3F
data: $1F
I still need to comment the code but will put it on my website when done.
Author of COBOS
Post Reply