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

Binary operations

Started by Velochy Jul 22, 2002 at 2:17 AM 3 replies 200+ views
Original Post
Velochy
Velochy
one question.. say a=10101101 and b=1010 would a & b return 10101000 or just 1000 ? also whats the use of these:
  
for(INT i = 0; i < 8; i++)
{
	dist = (i & 0x4) ? FAR_CLIP : NEAR_CLIP;
	t = (i & 0x2) ? t : -t;
	t = (i & 0x1) ? -t : t;
}
  
I am thinking the first would return true if number>=0 and false otherwise but i cant seem to figure out what the 2 others do
Gee
Gee
My question is how you declair b (the nibble) in C++ ?

And btw it will be 1000...
---GUI Programming Division Manager at Wildfire Gamesworking on the 0 A.D. project
Velochy
Velochy
i dont
they are just for this forum for arguments sake
Monder
Monder
You can''t declare a nibble because memory is addressed by the byte so the smallest thing you can declare is a byte(unsigned char in c/c++)
LessBread
LessBread
quote:
Original post by Velochy

for(INT i = 0; i < 8; i++)
{
dist = (i & 0x4) ? FAR_CLIP : NEAR_CLIP;
t = (i & 0x2) ? t : -t;
t = (i & 0x1) ? -t : t;
}

I am thinking the first would return true if number>=0 and false otherwise but i cant seem to figure out what the 2 others do


The first returns true if i >= 4 in the range 0-7. Examine the bit patterns below.

The result of the other two depend on t being predefined, in which case the sign is fliped accordingly, but watch the fall through.

& 0x2 & 0x1 t(n)
0:0000 F -t F t -t
1:0001 F -t T -t t
2:0010 T t F t t
3:0011 T t T -t -t
4:0100 F -t F t -t
5:0101 F -t T -t t
6:0110 T t F t t
7:0111 T t T -t -t
8:1000





[edited by - lessbread on July 22, 2002 6:51:07 AM]
"I thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man

Topic Locked

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

Sign in to reply to this topic.