August 2nd, 2003

sleepy

stages of a programmer with regard to bitwise operators

Newbie:

REG_WININ = 17;
REG_WINOUT = 1;
REG_DISPCNT |= 16384;
(and so on throughout the code, all carefully hand-calculated)

Beginner:

#define BIT1 1
#define BIT2 2
#define BIT3 4
#define BIT4 8
#define BIT5 16
(etc, etc, etc) (yes, I've seen this table taken all the way up to #define BIT32 2147483648)

Slightly-more-advanced beginner:

#define BIT0 1
#define BIT1 2
#define BIT2 4
#define BIT3 8
#define BIT4 16
(etc, etc, etc)

Intermediate:

#define BIT0 0x00000001
#define BIT1 0x00000002
#define BIT2 0x00000004
#define BIT3 0x00000008
#define BIT4 0x00000010
(etc, etc, etc)

There's actually a stage here which I will term "completely hopeless", and yes, I've seen people doing things like this:

#define BIT0 ((int)pow(2,0))
#define BIT1 ((int)pow(2,1))
#define BIT2 ((int)pow(2,2))
#define BIT3 ((int)pow(2,3))
#define BIT4 ((int)pow(2,4))
(etc, etc, etc)

Advanced:

#define KEYINPUT_A0x0001
#define KEYINPUT_B0x0002
#define KEYINPUT_SELECT0x0004
#define KEYINPUT_START0x0008
#define KEYINPUT_RIGHT0x0010
#define KEYINPUT_LEFT0x0020
#define KEYINPUT_UP0x0040
#define KEYINPUT_DOWN0x0080
#define KEYINPUT_R0x0100
#define KEYINPUT_L0x0200

(Look ma, MEANINGFUL LABELS)

Finally actually *intelligent*:

#define KEYINPUT_A(1<<0)
#define KEYINPUT_B(1<<1)
#define KEYINPUT_SELECT(1<<2)
#define KEYINPUT_START(1<<3)
#define KEYINPUT_RIGHT(1<<4)
#define KEYINPUT_LEFT(1<<5)
#define KEYINPUT_UP(1<<6)
#define KEYINPUT_DOWN(1<<7)
#define KEYINPUT_R(1<<8)
#define KEYINPUT_L(1<<9)


I'm *finally* consistently doing the last method . . . but boy did it take me a long time to realize the best way to handle this >_<

Unless there's a better way, of course, that I am totally missing. Ain't compsci great!

Yes, this is geek humor. :P

(And why is my LJ making the text in tables larger? Grrf. Go figure.)
sleepy

(no subject)

* BATCH1 (Batch1@ool-18bccb63.dyn.optonline.net) has joined #c++
<BATCH1> im haven problems maken the exe
<BATCH1> can some one help?

when a conversation starts like this, it never gets better.
  • Current Mood
    bang head here