Thread: int into bits Bitwise

  1. #46
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Quote Originally Posted by bdillion View Post
    another thrilling wrong addition by yourself there i think i proved my own point that your too up yourself to accept criticism yourself. I'm sure your go far with that attitude
    Actually, if you read the threads that I've started (seeking advice), you'll find that I am generally quite humble, open to honest criticism, and willing to accept when I am wrong. Moreover, if you look at all of my posts to this particular thread, it's pretty obvious that I was trying to help you. At any rate, right now you would really benefit by:

    1) Studying the language as much as possible in preparation for this assignment during the next few days (anything beats a zero grade, after all).
    2) Formulating your questions as concisely and clearly as possible, so as to maximize the quality of the responses that you receive.
    Last edited by Sebastiani; 05-19-2010 at 03:20 PM. Reason: grammer
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  2. #47
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by bdillion View Post
    I accept criticism however you are not helping your being an elitist prick, the other people in this thread are more than willing to explain it in terms i understand that i thank them for it
    Sure but we can't help you any further unless you actually slow down, read the replies, IGNORE the personality conflicts you percieve, and ANSWER questions, like the one I asked in post #35:

    Quote Originally Posted by MK27 View Post
    Umm -- if each square can be either X or O or empty (like tic tac toe), you cannot use that method. It will work if all the squares are either X or O and never "empty" (you never explained the rules of the game).
    Otherwise I and everybody else just feel we are wasting our time. I was somewhat paranoid and often frustrated when I first joined here -- skip it. Sebastiani is one of the nicest members around. And pretty talented to boot. Don't take criticism personally. Nobody is trying to f**k with you, but sometimes "getting to the point" can appear intimidating.

    I dunno if you are going to be able to finish this assignment in time, but if you can pull your head out of a tailspin you can at least make a decent attempt, and maybe then take that to your prof and ask for an extension of a few days to get it done right rather than rush it and fail anyway. A lot of profs will grant one extension per semester. But you are going to have to be tactful and keep your attitude in check there too.

    And please, please, please, don't get so upset. We know you are stressed out. That's nobodies fault as far as I am concerned, but don't make it worse for yourself.

    Slow down. Read. Respond carefully and clearly. Programming is hard. You need to remain calm. Your assignment is not that complicated and it can be done here. The only thing standing in your way is your communication skills.
    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

  3. #48
    Registered User jeffcobb's Avatar
    Join Date
    Dec 2009
    Location
    Henderson, NV
    Posts
    875
    Sound advice MK; lets see if he can take it. Being a good programmer is never measured by how you do when things are easy but rather how you do when your back in against the wall, you have poor requirements given to you (as kinda happened here) and you have a fixed time to still be a winner (or a winer).

    Our hero here can spend the supposedly few days he has left blaming others or he can take the help given him already and be done in an afternoon. Let's see how it turns out..
    C/C++ Environment: GNU CC/Emacs
    Make system: CMake
    Debuggers: Valgrind/GDB

  4. #49
    Registered User
    Join Date
    May 2010
    Posts
    21
    ok i appolgise, moving on

    i was sent some hint sheets today because the amount of people complaining, and there vastly different from what we have discussed.

    Im reading them atm will get back when i have a clearer picture. My idea is to work out if the board position is filled with aidata or player data then set a bit to 0 or 1 which is stored ina bit array with 16 bits 1 for position 1 for the type so the out put will be as follows

    if we have a grid

    x--
    ---
    ---

    the out put would be

    x= 1 0= 0

    11 00 00
    00 00 00
    00 00 00

  5. #50
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Quote Originally Posted by bdillion View Post
    ok i appolgise, moving on

    i was sent some hint sheets today because the amount of people complaining, and there vastly different from what we have discussed.

    Im reading them atm will get back when i have a clearer picture. My idea is to work out if the board position is filled with aidata or player data then set a bit to 0 or 1 which is stored ina bit array with 16 bits 1 for position 1 for the type so the out put will be as follows

    if we have a grid

    x--
    ---
    ---

    the out put would be

    x= 1 0= 0

    11 00 00
    00 00 00
    00 00 00
    Right, so to access the Nth bit (using 0-based indexing) you can simply create a bitmask with the value of 1 bit-shifted left by N, and then use that mask to test (using bitwise AND) or set (using bitwise OR) the integer holding the data.
    Last edited by Sebastiani; 05-19-2010 at 04:21 PM. Reason: quotes removed, for clarity
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  6. #51
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    I still don't understand the nature of the game -- is it like tic tac toe, or what?
    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

  7. #52
    Registered User
    Join Date
    May 2010
    Posts
    21
    yeah its suppose to be tic tac toe, most of it was pre-coded which makes it more difficult as i can never see what he's doing with his code

  8. #53
    Registered User
    Join Date
    May 2010
    Posts
    21
    this is my code so far
    i set a bit array for position and one for x or 0 however it seems to think there is somthing in the board position even when theres not, its going to be a long night

    Code:
    void pack()
    	{
    
    
    GameData game = new GameData;
    
    	bitset<15> bits;	// holds the symbol type		
    		bits[0];
    		bits[1];
    		bits[2];
    		bits[3];
    		bits[4];
    		bits[5];
    		bits[6];
    		bits[7];
    		bits[8];
    		bits[9];
    		bits[10];
    		bits[11];
    		bits[12];
    		bits[13];
    		bits[14];
    		bits[15];
    
    
    		bitset<15> bp; // holds board position
    		bp[0];
    		bp[1];
    		bp[2];
    		bp[3];
    		bp[4];
    		bp[5];
    		bp[6];
    		bp[7];
    		bp[8];
    		bp[9];
    		bp[10];
    		bp[11];
    		bp[12];
    		bp[13];
    		bp[14];
    		bp[15];
    
    
    
    
    		if (board[0] != 0)
    		{		
    			bp[0] = 1;
    			if(game.aiData == board[0])
    			{
    				cout<<"ai went here";
    				bits[0] = 1;
    			}
    			else
    			{
    				cout<<"player went here";
    				bits[0] = 0;
    			}
    
    		}
    
    
    	}

  9. #54
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Being more of a pure C guy, I had forgotten about bitset. That will make your life easier.

    Just to make sure I and everyone understand then:

    Code:
    	bitset<15> bits;	// holds the symbol type
    Small problem: this is a set of 15 bits, indexed 0-14. You want a set of 16 bits, indexed 0-15. Now what is the purpose here:
    Code:
    		bits[0];
    		bits[1];
    		bits[2];
    ...etc.
    You don't have to do that, the bits are initialized to zero (not sure what your purpose is...)

    Anyway, so I am guessing by "holds the symbol type" you mean this indicates whether this position has an X or an O. Which doesn't deal with empty, so:

    Code:
    		bitset<15> bp; // holds board position
    Is the purpose of that (again, it should be 16) to indicate whether a square is occupied or not?
    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

  10. #55
    Registered User
    Join Date
    May 2010
    Posts
    21
    hey

    bits[0];
    bits[1];
    bits[2];

    purpose was i thought they acted like as if the numbers were there position in the array

    and yes the number of bits was wrong i forgot it starts at 0

  11. #56
    Registered User jeffcobb's Avatar
    Join Date
    Dec 2009
    Location
    Henderson, NV
    Posts
    875
    Um, didn't we figure out that a bit is insufficient for this (the three states needed)? Would you like a working class to manage all of this that is debugged and ready to be used?
    C/C++ Environment: GNU CC/Emacs
    Make system: CMake
    Debuggers: Valgrind/GDB

  12. #57
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by bdillion View Post
    purpose was i thought they acted like as if the numbers were there position in the array
    They exist automatically. It's like this:
    Code:
    int array[10];
    That's ten ints and you can access them in order, array[0] to array[9]. But by declaring it as "int array[10]" it contains them already.

    Usually array elements are not initialized to any particular value (meaning they could be anything) but bitsets I believe are initialized so that everything starts with a value of zero.

    Quote Originally Posted by jeffcobb View Post
    Um, didn't we figure out that a bit is insufficient for this (the three states needed)?
    Still trying to determine how bdillion intends to deal with this. Looks to me like there will be one bitset to indicate if a square is occupied, and then (if so) one to indicate whether it contains X or O.
    Last edited by MK27; 05-19-2010 at 05:33 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

  13. #58
    Registered User
    Join Date
    May 2010
    Posts
    21
    emailed my lecturer and he said 2 bytes is all u need 1 for each position 1 for each symbol, however 9 squares 9 potential symbols 9x9 = 18 thats 2 bytes and 2 bits?

  14. #59
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by bdillion View Post
    emailed my lecturer and he said 2 bytes is all u need 1 for each position 1 for each symbol, however 9 squares 9 potential symbols 9x9 = 18 thats 2 bytes and 2 bits?
    No, if there are nine squares and you need 2 bits per position, that's 9x2 = 18 bits.

    You could organize that several different ways, but I would stick to two arrays of 9 bits. The first array will indicate whether a square is occupied (1) or not (0). The second one will indicate what symbol is in the square (say 0 = O, 1 = X). That means the first one supersedes the second one, because otherwise the second one would initially indicate a board of all O's -- get it?
    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

  15. #60
    Registered User jeffcobb's Avatar
    Join Date
    Dec 2009
    Location
    Henderson, NV
    Posts
    875
    I have contributed all that I can to this goose chase; with about 10 lines of code he could take what I gave him and be done. I have an IPC server and an autoptr class to get going by tomorrow...
    C/C++ Environment: GNU CC/Emacs
    Make system: CMake
    Debuggers: Valgrind/GDB

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. NEED HELP READING FILE and PRINTING
    By geoffr0 in forum C Programming
    Replies: 4
    Last Post: 04-16-2009, 05:26 PM
  2. memory leak
    By aruna1 in forum C++ Programming
    Replies: 3
    Last Post: 08-17-2008, 10:28 PM
  3. Replies: 26
    Last Post: 11-30-2007, 03:51 AM
  4. newbie needs help with code
    By compudude86 in forum C Programming
    Replies: 6
    Last Post: 07-23-2006, 08:54 PM
  5. getting a headache
    By sreetvert83 in forum C++ Programming
    Replies: 41
    Last Post: 09-30-2005, 05:20 AM