Thread: Bits byte

  1. #31
    Registered User Azmeos's Avatar
    Join Date
    Jun 2003
    Thanks guys, for helping me... however... when I tried JawiB's code, it runs each one 7 times... which I don't want. it should run it once, checking through each one 7 times. here's the updated code...

    PHP Code:
            unsigned char mask[] = {0x800x400x200x100x080x040x020x01};

    int binValue 0;
    int j 0;
    int stride = (imageWidth 7) / 8;
    unsigned charrowBuff, *pixByte;

    int k=0imageLengthk++)
    rowBuff buf stride k;
    int i=0imageWidthi++)
    pixByte rowBuff + (8);
    cout << " -" << (int)*pixByte << "-" << endl;

    binValue = ((*pixByte mask[j]) ? );
    cout << binValue;
    cout << endl;
    Is my mask wrong? Or is something else wrong?

    By the way... I am getting strange results for (int)*pixByte ... sometimes I will get something like one of these: 31, 13, 30, or 63. The rest are 0s and 255s (which they should be). Anyone have an explaination?
    Last edited by Azmeos; 07-17-2003 at 11:38 AM.

  2. #32
    Registered User Azmeos's Avatar
    Join Date
    Jun 2003
    Can anyone help me?

  3. #33
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Don't bump.
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ

  4. #34
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Originally posted by quzah
    Slight correction here on your code:

    return !!(number & 1 << bitIndex);

    Without the double not statement, you are not actually returning a boolean value. The only way you would, would be if bitIndex was zero. Anything else does not return 1. It returns a power of two.

    While it is true that it would work for an equality test, where anything non-zero is considered true, in your case, it is incorrect, because bool should only ever be one or zero.

    This would fail:

    if( testBit( 2, 1 ) == 1 )

    Because "number & 2" would return two, not one.


    Wait a moment, I think that would be buggy compiler behavior. bool is a built-in type in C++ that can only have the states true (1) and false (0).
    That means if I do:
    bool retBool()
      return 3;
    int main()
      cout << (int)retBool() << endl;
      return 0;
    VC++ will issue a warning (truncation cast, possible data loss) but will compile and output "1". That's because the 3 gets converted to boolean true and then to integer again, resulting in 1.
    That's VC++7.1, about the most standards compliant compiler out there.
    All the buzzt!

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  5. #35
    Registered User Azmeos's Avatar
    Join Date
    Jun 2003
    For all of you who were helping me with it, thanks... I figured it out!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. SDLKey to ASCII without unicode support?
    By zacs7 in forum Game Programming
    Replies: 6
    Last Post: 10-07-2007, 03:03 AM
  2. brace-enclosed error
    By jdc18 in forum C++ Programming
    Replies: 53
    Last Post: 05-03-2007, 05:49 PM
  3. About aes
    By gumit in forum C Programming
    Replies: 13
    Last Post: 10-24-2006, 03:42 PM
  4. byte is equal 8 bits???
    By Micko in forum C Programming
    Replies: 3
    Last Post: 10-15-2004, 10:12 AM
  5. error: identifier "byte" is undefined.
    By Hulag in forum C++ Programming
    Replies: 4
    Last Post: 12-10-2003, 05:46 PM