Skip to main content
GameDev.net gamedev.net
🔒 Locked

Bits

Started by Viscous-Flow Oct 22, 2001 at 5:57 PM 8 replies 500+ views
Original Post
Viscous-Flow
Viscous-Flow
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!
Shannon Barber
Shannon Barber
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
Viscous-Flow
Viscous-Flow
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!
EvilCrap
EvilCrap
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
Dactylos
Dactylos
are you aware of the fact that ^ means bitwise xor in C/C++?

2^3 = 1
EvilCrap
EvilCrap
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
Oluseyi
Oluseyi
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 
Shannon Barber
Shannon Barber
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
Oluseyi
Oluseyi
Magmai: thanks!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.