Bits

Started by
8 comments, last by Viscous-Flow 22 years, 6 months ago
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!
Advertisement
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
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
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!
Some programs set the targa''s vertical origin bit incorrectly. It''s really annoying.

[Resist Windows XP''s Invasive Production Activation Technology!]
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
are you aware of the fact that ^ means bitwise xor in C/C++?

2^3 = 1
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
quote:Original post by EvilCrap
WHOPS!

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

If it''s exponentiation of 2, use bitshifts:
23 = 2 << 3 = 8 
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
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
Magmai: thanks!

This topic is closed to new replies.

Advertisement