Challenge: Make a data type for holding one of 8 directions allowing increment and overflow
Richard (Rikki) Andrew Cattermole
richard at cattermole.co.nz
Tue Mar 12 22:10:33 UTC 2024
On 13/03/2024 11:00 AM, Liam McGillivray wrote:
> I'm not familiar with the syntax of the line |value &= 7;|. Is it
> equivalent to writing |value = value % 7;|?
& is a bitwise and.
LSB 123456789 MSB
& 7
LSB 123000000 MSB
> Anyway, you used an int, but I used an array of 3 bools. I'm guessing
> that mine uses less memory, but I'm not sure how memory it adds when
> it's a struct with functions.
Due to alignment, it'll probably use just as much.
Mine only needs a single ``byte``, at 7 bits it's more than enough.
But ``int`` doesn't make much difference unless you are packing
instances together ``align(0):`` and realistically cpus are optimized
for 32bits not 8.
More information about the Digitalmars-d-learn
mailing list