Bit subscriptions, RAM columnwise layouts

Steven Schveighoffer schveiguy at yahoo.com
Thu Dec 11 13:20:29 PST 2008


"bearophile" wrote
> Subscription operators
> Wirbel lets you use an integer a little bit like a list of boolean values 
> with the fixed length of 32 or 64. You can used the square brackets to 
> directly address the bits:
>
> a = 0
> a[0] = true
> a[2] = false
> print(a)
>
> This will output 5 since this first bit (value 1) and the third bit (value 
> 4) have been switched on. You can also query arbitrary bits:
>
> if a[4]:
>    print("Bit 4 is on -> a contains a 16")
>
> Splices [slices] won't currently work but may follow in a later release of 
> Wirbel.
>>>
>
> For D the following is an alternative syntax seems a little more explicit:
> int a = 156;
> a.bits[0] = true;
> a.bits[0..5] = 0;
>
> Instead of:
> int a = 156;
> a[0] = true;
> a[0..5] = 0;
>

I like it.  a.bits[1..5] = 0 looks a hell of a lot better than a &= ~(((1 << 
4) - 1) << 1)

-Steve 





More information about the Digitalmars-d mailing list