Bits byte

This is a discussion on Bits byte within the C++ Programming forums, part of the General Programming Boards category; Thanks guys, for helping me... however... when I tried JawiB's code, it runs each one 7 times... which I don't ...

  1. #31
    Registered User Azmeos's Avatar
    Join Date
    Jun 2003
    Posts
    65
    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;

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

                    if(
    70;                            
                    
    binValue = ((*pixByte mask[j]) ? );
                    
    cout << binValue;
                    
    j++;
                }
                
    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 12:38 PM.
    \0

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

  3. #33
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    Don't bump.
    benforbes@optusnet.com.au
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  4. #34
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    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.

    Quzah.

    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:
    Code:
    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!
    CornedBee

    "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
    Posts
    65
    For all of you who were helping me with it, thanks... I figured it out!

Page 3 of 3 FirstFirst 123
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, 04:03 AM
  2. brace-enclosed error
    By jdc18 in forum C++ Programming
    Replies: 53
    Last Post: 05-03-2007, 06:49 PM
  3. About aes
    By gumit in forum C Programming
    Replies: 13
    Last Post: 10-24-2006, 04:42 PM
  4. byte is equal 8 bits???
    By Micko in forum C Programming
    Replies: 3
    Last Post: 10-15-2004, 11:12 AM
  5. error: identifier "byte" is undefined.
    By Hulag in forum C++ Programming
    Replies: 4
    Last Post: 12-10-2003, 05:46 PM

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