Thread: Some Bit Issures, Confused?

  1. #1
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465

    Some Bit Issures, Confused?

    I'm trying to set up an 8bit palette and it's being fussy

    Code in question - crap trimmed out

    Code:
        // 3 - 3 - 2 bit layout for palette
    
        for(unsigned char color = 0; color < 255; color++)
        {
            int greenzone = color & 0xE0;    // 11100000
            int redzone = color & 0x1C;        // 00011100
            int bluezone = color & 0x03;    // 00000011
    
            bitset<3> b(greenzone); cout << b << " ";
            bitset<3> c(redzone); cout << c << " ";
            bitset<2> d(bluezone); cout << d << " ";
            bits << "\t" << bitset<8>(color) << std::endl;
        }

    Yielding - note my markup, information loss, confuzion, blergh

    Code:
    000 000 00     00000000
    000 000 01     00000001
    000 000 10     00000010
    000 000 11     00000011
    000 100 00     00000100 * // Why on the left
    000 100 01     00000101
    000 100 10     00000110
    000 100 11     00000111
    000 000 00     00001000 * // Why
    000 000 01     00001001
    000 000 10     00001010
    000 000 11     00001011
    000 100 00     00001100
    000 100 01     00001101
    000 100 10     00001110
    000 100 11     00001111
    000 000 00     00010000
    000 000 01     00010001
    Why are the two columns different (no not the spacing, the data)

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    You need to shift the bits before placing them in the bitsets.

    For example, if color is 00000100, then greenzone is 00000000, redzone is 00000100 and bluezone is 00000000. Obviously b and d become 0, but c is a 3 bit value initialized with 00000100. That means c becomes 100.

    If you shift the bits first, then assign them to the bitset, you will get the appropriate values. You can do this before or after assigning to the zone variables. 00000100 >> 2 is 00000001, which when assigned to the c bitset will be 001. That's what you want. Of course, you'd have to bit shift the greenzone by more than 2.

  3. #3
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    Oo. Thanksy.

  4. #4
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    Just thought I'd share the fruits of my labours.

    http://img.photobucket.com/albums/v2...Picture026.jpg
    http://img.photobucket.com/albums/v2...o1/shadazz.jpg
    http://img.photobucket.com/albums/v2...o1/swiggle.jpg

    Kool 8bit palette + my 8bit shrine. Atari + NES not pictured, because I left them at home (in college now)

  5. #5

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 32 bit to 64 bit Ubuntu
    By Akkernight in forum Tech Board
    Replies: 15
    Last Post: 11-17-2008, 03:14 AM
  2. 32 bit or 64 bit allignment ?! gcc options??
    By mynickmynick in forum C Programming
    Replies: 3
    Last Post: 07-29-2008, 02:43 AM
  3. Replies: 16
    Last Post: 11-23-2007, 01:48 PM
  4. A Question About Unit Testing
    By Tonto in forum C++ Programming
    Replies: 2
    Last Post: 12-14-2006, 08:22 PM