RE: [Bitfields]How do I display them?

From: Gary Barnett (gbarnett@polarnet.com)
Date: 01/13/97


On Monday, January 13, 1997 12:32 PM, Wyatt Bode wrote:
>Hello all,
>        I have partially converted my MUD to bitfields, and I was
>wondering
>what the best way is to print them out.  Here's what I have now:
>
>void test_print(struct char_data *temp)
>{
>        int i, *j;
>
>        CLEAR_BITS(PLR_FLAGS(temp));
>
>        /* just a test, set some bits */
>        SET_BIT(PLR_FLAGS(temp), PLR_KILLER);
>        SET_BIT(PLR_FLAGS(temp), PLR_LOADROOM);
>        
>        for (i = 0, j = (int*) &PLR_FLAGS(temp); i <
>sizeof(PLR_FLAGS(temp));
>i++) {
>                printf("Bit #%2i == %3s\n", i, ONOFF(j[i]));
>        }
>}
>
>And here's the output:
>
>Bit # 0 ==  ON
>Bit # 1 == OFF
>Bit # 2 == OFF
>Bit # 3 == OFF
>
>It seems to be reading the values as full integers (like I told it to
>:->) but how can I get it to step through each bit?  I have tried other
>varieties of data types, but to no avail.  Any help wold be most
>appreciated.  Thanks in advance...
>                -- Wyatt Bode

Can't you just use sprintbit? Here's the declaration.. appears in utils.c

void sprintbit(long bitvector, char *names[], char *result)   

Certainly a good place to look for ideas on how to get at the bits if nothing else...

Regards,

--Mallory

-- http://www.polarnet.com/Users/gbarnett/ -- telnet://204.119.24.14:4000
+-----------------------------------------------------------+
| Ensure that you have read the CircleMUD Mailing List FAQ: |
|   http://cspo.queensu.ca/~fletcher/Circle/list_faq.html   |
+-----------------------------------------------------------+



This archive was generated by hypermail 2b30 : 12/18/00 PST