PDA

View Full Version : Larger Bitfields


futureal
Sat 6th Dec '03, 8:57pm
Is there an accepted way (or data type) to allow for more than 32 (2^31) values in a bitfield variable?

I am writing a CMS for one of my websites and was going to use a bitfield for category access control (on the admin side, e.g. who can post to what category) but I'd like it to be able to scale up as more categories are added. Obviously a limit of 32 categories is undesirable.

Possible to do with bitfields, or bad idea? Thanks!

Scott MacVicar
Sat 6th Dec '03, 9:06pm
You can make the bitfield a LARGEINT and also make it Unsigned.

That should let you have
2^64

Faruk
Mon 8th Dec '03, 5:51am
Sounds like a weird setup, to me... If you add multiple categories, shouldn't they go into new rows in a database table, instead of stacked in one row as a bitfield? o_O

Freddie Bingham
Mon 8th Dec '03, 11:42am
Sounds like a weird setup, to me... If you add multiple categories, shouldn't they go into new rows in a database table, instead of stacked in one row as a bitfield? o_O
Some people would agree with you about columns and some wouldn't.

As for the size, if you have a 32 bit system, PHP's INT only functions up to 32 bits. It casts to a float for anything over that and you can bit-switch a float.

futureal
Mon 8th Dec '03, 11:19pm
Sounds like a weird setup, to me... If you add multiple categories, shouldn't they go into new rows in a database table, instead of stacked in one row as a bitfield? o_OI have an application that will require about 40 different boolean settings, all control variables, on or off -- 1 or 0. Each entry into this table will require its own set of settings, so to me, it seems that bitfields are the best way to accomplish this, since I can then have one or two integer fields that will contain all of my settings.

If you can think of a better way to do it, then by all means enlighten me...

Thanks for the information, guys.