[dorkbotpdx-blabber] A puzzle for you. In C. This is just for fun.

28 views
Skip to first unread message

David Turnbull

unread,
Apr 6, 2013, 4:39:31 PM4/6/13
to A discussion list for dorkbot-pdx (portland, or)
Can you explain what this C macro is for? The correct answer will include the type of data it operates on, how it is represented to the macro, and what the macro does to it. I will post a clue tomorrow and the answer after dorkbot on Monday. You can also ask me about it at dorkbot. Feel free to discuss it here on blabber. I will reply if someone posts a complete enough answer but expect me to remain silent otherwise.

#define DATA_L(x) (((x&0x0000000FLU)?1:0)\
+((x&0x000000F0LU)?1:0)\
+((x&0x00000F00LU)?1:0)\
+((x&0x0000F000LU)?1:0)\
+((x&0x000F0000LU)?1:0)\
+((x&0x00F00000LU)?1:0))
#define DATA_C(x) (((x&0x00000002LU)?1:0)\
+((x&0x00000020LU)?2:0)\
+((x&0x00000200LU)?4:0)\
+((x&0x00002000LU)?8:0)\
+((x&0x00020000LU)?16:0)\
+((x&0x00200000LU)?32:0))
#define DATA_6(x) (((x&0x00F00000LU)?4:0)\
+ ((((x&0x00F00000LU)?1:0) & ((x&0x00000002LU)?0:1))?2:0))
#define DATA(d)((uint8) (d==0)?7:DATA_L(0x##d##LU)\
+ (DATA_C(0x##d##LU) << 8 - DATA_L(0x##d##LU))\
- DATA_6(0x##d##LU))

David Turnbull

unread,
Apr 7, 2013, 6:17:43 PM4/7/13
to A discussion list for dorkbot-pdx (portland, or)
Here's the clue I promised. This demonstrates how information is presented to the macro. The table below is only a sample of a larger table. It's the first 20 entries from the application I will post tomorrow.

const uint8 TABLE[] = {
    DATA(131131),
    DATA(0),
    DATA(0),
    DATA(0),
    DATA(0),
    DATA(133331),
    DATA(31331),
    DATA(313313),
    DATA(0),
    DATA(13131),
    DATA(331133),
    DATA(311113),
    DATA(131313),
    DATA(31131),
    DATA(33333),
    DATA(13333),
    DATA(11333),
    DATA(11133),
    DATA(11113),
    DATA(11111)
Reply all
Reply to author
Forward
0 new messages