piont me in the right direction please

This is a discussion on piont me in the right direction please within the C Programming forums, part of the General Programming Boards category; Hello, Sorry for bothering yall with something like this but, yall pros always have the best website knowledge. I was ...

  1. #1
    Registered User
    Join Date
    Dec 2008
    Posts
    14

    piont me in the right direction please

    Hello,

    Sorry for bothering yall with something like this but, yall pros always have the best website knowledge. I was wondering if anyone knew a good page that helps learning bitvectors. I am pretty comfortable with coding know but am lost when it comes to bits and binary. Exp. I am learning the tbamud code and it uses binary flags for player toggles, preferences, affect flags and much more.

    It works on a 128-bit binary flag system, and right there I am lost.


    Thank you for any advice or redirection given, it is very much apprciated.
    Cindy
    Last edited by clb2003; 03-02-2009 at 01:52 PM.

  2. #2
    Registered User ralu.'s Avatar
    Join Date
    Feb 2009
    Location
    Bucharest, RO
    Posts
    32
    If by "bitvectors" you mean bit fields than here it is what you can find on wikipedia:

    http://en.wikipedia.org/wiki/Bitfield
    http://www.cs.cf.ac.uk/Dave/C/node13.html
    I have stopped reading Stephen King novels. Now I just read C code instead.

  3. #3
    Registered User
    Join Date
    Dec 2008
    Posts
    14
    Thank you very much. I am not 100% sure if that is what he meant, here is how he told me. This was the question I first asked.

    Why do alot of define's shift the operands?

    Code:
    /* Exit info: used in room_data.dir_option.exit_info */
    #define EX_ISDOOR     (1 << 0)   /**< Exit is a door		*/
    #define EX_CLOSED     (1 << 1)   /**< The door is closed	*/
    #define EX_LOCKED     (1 << 2)   /**< The door is locked	*/
    #define EX_PICKPROOF  (1 << 3)   /**< Lock can't be picked	*/
    This is the response he gave me.


    These are used for binary flags (often called bitvectors in the MUD code). These are used a lot in the MUD code, for player toggles, preferences, affect flags and much more. They are defined like this because it makes it easier to read than 1, 2, 4, 8, 16, 32, 64, etc... You can see at a glance how many flags you have, just by looking at how many shifts to the left are done on the last flag.

    tbaMUD works on a 128-bit binary flag system, although it's expandable to almost as many bits as you want. An integer is made up of 32 binary digits, so a 'bitvector' variable is usually an array of 4 integers.

    The old CircleMUD didn't have 128-bit flags - it was limited to 32-bits. For this reason, where CircleMUD used the IS_SET(var, flag) flag check, and the SET_BIT, REMOVE_BIT and TOGGLE_BIT handlers, these couldn't be totally removed. In the above, 'var' was a single integer value, consisting of 32 flags.

    New defines were therefore created to handle an array of integers to be used as flags. These are IS_SET_AR, SET_BIT_AR, REMOVE_BIT_AR and TOGGLE_BIT_AR. When dealing with integer arrays, these should be the ones to use.

  4. #4
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Do a tutorial on bitshifting, bitfields or bitmasks and you'll figure it out. They are very common in C and you have certainly been using them without knowing it, eg:
    Code:
    open(file, O_RDONLY);
    O_RDONLY is a bitmask.

    I'm sure the fact that "It works on a 128-bit binary flag system" is really irrelevant, so don't worry about it (that's a lot of flags I guess).

    I am not 100% sure if that is what he meant
    I am, for what that is worth. But I don't think you will find the term "bitvector" used very much, is all. It is the same thing (an array of bit values).
    Last edited by MK27; 03-02-2009 at 02:11 PM.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,589
    Ah yes, you are really looking at a bit vector. Imagine if you wanted to record up to 128 "yes/no" options. One way is to create an array of 128 ints, and then designate 0 for "no" and 1 for "yes". The bit vector here works on the same concept, except that instead of using 128 ints, it uses 128 bits stored in an array of just 4 ints, each int presumably being of 4 bytes, and each byte presumably being of 8 bits. Of course, this means that instead of accessing the options via an array, you now access the options using bitwise operations (and some array operations to get to the desired int).
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  6. #6
    Registered User
    Join Date
    Dec 2008
    Posts
    14
    Thank you so very much for you very timely answers once agin, always get the nicest and best answers from the forums here.

    Thank you agin fellows, looking for some tutorials now.

  7. #7
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,047
    "bitvector" is more commonly known as a "bitmap".

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Some Direction Needed
    By Bidamin in forum C++ Programming
    Replies: 3
    Last Post: 04-22-2009, 10:15 AM
  2. Mouse Maze Problem
    By Furbiesandbeans in forum C++ Programming
    Replies: 13
    Last Post: 04-28-2008, 04:20 PM
  3. Algorithm to walk through a maze.
    By Nutshell in forum C Programming
    Replies: 30
    Last Post: 01-21-2002, 12:54 AM
  4. direction in directx
    By Unregistered in forum Game Programming
    Replies: 1
    Last Post: 12-24-2001, 07:03 AM
  5. Classic problem doesn't accept direction
    By cheesehead in forum C++ Programming
    Replies: 5
    Last Post: 11-13-2001, 05:32 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21