#define RC_STATE(value) value & 0x1
#define RC_DEVICE(value) (value >> 1) & 0x1F
#define RC_GROUP(value) (value >> 6) & 0x1F

struct RcDecoder {
    bool state;
    char group;
    unsigned char device;

    void decode(unsigned long value) {
        value = value >> 2;
        unsigned long res = 0;
        for (int i = 0; i < 12; i++) {
            res |= ((value & 1) ^ 1) << i;
            value = value >> 2;
        }

        state = RC_STATE(res);
        group = RC_GROUP(res);
        switch (RC_DEVICE(res)) {
        case 0b10000:
            device = 1;
            break;
        case 0b01000:
            device = 2;
            break;
        case 0b00100:
            device = 3;
            break;
        case 0b00010:
            device = 4;
            break;
        case 0b00001:
            device = 5;
            break;
        }
    }
};
