carcassonne has asked for the wisdom of the Perl Monks concerning the following question:
Is there a way to give names to bits as in a byte bit field whose every bit would have a meaning that could be set by a subroutine, like:
setStatus(powerOn);
... which would set the powerOn bit in a 8-bit status byte. This bit could be the first one, bit 0. Then we could have:
setStatus(lightOn);
Which would set another status bit in the same status byte while not modifying the other set/unset bits. So on so forth.
Is there some kind of enum type in Perl to do that ? Or can it be done using a hash ?
Thanks.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Giving names to bits
by Tanktalus (Canon) on Feb 23, 2007 at 03:11 UTC | |
by carcassonne (Pilgrim) on Feb 23, 2007 at 12:46 UTC | |
by Tanktalus (Canon) on Feb 23, 2007 at 14:52 UTC | |
|
Re: Giving names to bits
by Zaxo (Archbishop) on Feb 23, 2007 at 03:14 UTC | |
|
Re: Giving names to bits
by varian (Chaplain) on Feb 23, 2007 at 09:15 UTC |