Archived

This topic is now archived and is closed to further replies.

Viscous-Flow

Bits

Recommended Posts

Hello, Is this the proper way to determine whether or not bit 5 in this byte is 0 (also the array is an unsigned char): If the bit is 0 then I proceed to flip the image - I get this information to check the fifth bit in the 17th offset to flip the TGA image from here.
  
//  This checks to see if the fifth bit in the 17th offset is 0

//  If it is then the image is upside down so we need to flip it

if((tgaInfo[5] & (1 << 11) ? 0 : 1))
{
	if(flipImageVertically() == NULL)
		return 0;
}
  
Thanks for your help!

Share this post


Link to post
Share on other sites
Well, um no.

I think they mean the 17th byte
    
const DWORD bit5 = 0x00000010;

if(tgaInfo[17] & bit5)
{//Bit 5 is SET

}
else
{//Bit 5 is NOT set

}



Magmai Kai Holmlor
- Not For Rent

[edit, oops]

Edited by - Magmai Kai Holmlor on October 22, 2001 7:10:11 PM

Share this post


Link to post
Share on other sites
Oh, thanks, but the 5 in the tgaInfo[5] has no bearing since it IS the 17th byte; it doesn''t mean the fifth byte, just thought I''d clear that up.

The strange thing is that this peice of code works with all the other TGA''s I''ve loaded, but I just got this one that doesn''t work with it. So either it was saved improperly by whatever program made it or my code is wrong.

Thanks again!

Share this post


Link to post
Share on other sites
im sure ur way is probably more standardized than mine...
BUT, isnt it easier to write it using math instead of shifts?
like:


x |= 2 ^ 3;
if ( x & 2 ^ 3 ) ...
the compiler should optimize 2 ^ 3= 8
Is this any slower than shifts?



#define b(x) 2 ^ x //obviously, the compiler cant always optimize this into a literal -would this macro be slower than shift?


Edited by - evilcrap on October 22, 2001 7:28:54 PM

Share this post


Link to post
Share on other sites
WHOPS!

u know what i mean, pow()... or whatever the thing is called

Edited by - evilcrap on October 22, 2001 7:30:44 PM

NEVER MIND -IM A MORON


Edited by - evilcrap on October 22, 2001 7:35:13 PM

Share this post


Link to post
Share on other sites
Oluseyi,I think you meant:
1 << 3 = 8
2 << 3 = 16
:p easy mistake to make

Magmai Kai Holmlor
- Not For Rent


And _the easiest way is to bitwise-and with a const of the bit or bits you care about!


Edited by - Magmai Kai Holmlor on October 23, 2001 1:11:58 AM

Share this post


Link to post
Share on other sites