multiple booleans stored in 1-byte


Does anyone know how I could do this?

For three booleans, x, y, and z:

Byte Boolean=True
0..... (none)
1..... x
2..... y
3..... z
4..... x, y
5..... x, z
6..... y, z
7..... x, y & z

I could do this manually, but I would prefer to define a type or something so I can create as many 3-set booleans in my progs.

[italic][blue]-- Spida.[/blue][/italic]

Comments

  • not sure if this is what you want but try the search facility on "bit operator"

  • :
    : Does anyone know how I could do this?
    :
    : For three booleans, x, y, and z:
    :
    : Byte Boolean=True
    : 0..... (none)
    : 1..... x
    : 2..... y
    : 3..... z
    : 4..... x, y
    : 5..... x, z
    : 6..... y, z
    : 7..... x, y & z
    :
    : I could do this manually, but I would prefer to define a type or something so I can create as many 3-set booleans in my progs.
    : [italic][blue]-- Spida.[/blue][/italic]

    i'm sure you're aware that in c (or maybe just c++) there's a predefined type called bit, which literally takes up a bit.
    and you can make a struct (record) called byte that would have 8 bits and then union that with another 1-byte type to preform bitwise operations and whatever, so maybe there's something equivalent to 'bit' in pascal (even though i think i've looked)..
    if there were function overloading in pascal you could overload the '=' to be able to determine if a record containing booleans is 'true'..or something..

    but you could use [italic]set[/italic]s, to make 3 vars that are either 0 or 1, put them together in a record and make a function that will return 0..7 depending on which are true.. (or just use 3 actual booleans in a record with that same function..)
    but none of this will of course take up only 1 byte.. but it doesn't seem like such a bad idea to me.. so if you find a better way lemme know :)


    **********
    Make something idiot proof and some1 will make a better idiot..
    [blue]//Noam[/blue]


  • : but you could use [italic]set[/italic]s, to make 3 vars that are either 0 or 1, put them together in a record and make a function that will return 0..7 depending on which are true.. (or just use 3 actual booleans in a record with that same function..)
    : but none of this will of course take up only 1 byte.. but it doesn't seem like such a bad idea to me.. so if you find a better way lemme know :)

    Actually that would be a good idea. It doesn't bother me that it will take 3 or more bytes in memory, it's so I can write it to a file and minimise disk space, and lessen the chance of the file becoming incompatible with different settings.

    Thanx :-) for the idea

    [italic][blue]-- Spida.[/blue][/italic]


Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories