Jump to content
  • Advertisement
Sign in to follow this  
willthiswork89

Whats this symbol?

This topic is 4521 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

i got a good tutorial on smooth scrolling and the writer used this map_xoff = map_drawx & 15; whats the AND symbol mean? and if its not c++.. what symbol would i use for c++?

Share this post


Link to post
Share on other sites
Advertisement
If I'm wrong, don't shoot me. It's hard to tell what the & is trying to do since I have no idea what the rest of the code is doing. But I'm going to go along and assume its the bitwise AND operator in c++. Here is a thing straight from http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclang/html/_pluslang_bitwise_and_operator.asp

C++ Language Reference   

Bitwise AND Operator: &
Grammar

and-expression:
equality-expression
and-expression & equality-expression
The bitwise AND operator (&) compares each bit of the first operand to the
corresponding bit of the second operand. If both bits are 1, the corresponding
result bit is set to 1. Otherwise, the corresponding result bit is set to 0.

Both operands to the bitwise AND operator must be of integral types. The usual
arithmetic conversions covered in Arithmetic Conversions, are applied to the
operands.

Operator Keyword for &

The bitand operator is the text equivalent of &. There are two ways to access
the bitand operator in your programs: include the header file iso646.h, or
compile with the /Za (Disable language extensions) compiler option.

Example
// expre_Bitwise_AND_Operator.cpp
// compile with: /EHsc
// Demonstrate bitwise AND
#include <iostream>
using namespace std;
int main() {
unsigned short a = 0xFFFF; // pattern 1111 ...
unsigned short b = 0xAAAA; // pattern 1010 ...

cout << hex << ( a & b ) << endl; // prints "aaaa", pattern 1010 ...
}




EDIT: shoot you barely beat me to it

Share this post


Link to post
Share on other sites
In that context, you should/could also write
map_xoff = map_drawx % 16;

This would be more consistant with tiling because you have
const int TILE_SIZE = 16;
mapx = map_drawx / TILE_SIZE;
map_xoff = map_drawx % TILE_SIZE;


% would be the modulos operator (like a remainder in math).

Share this post


Link to post
Share on other sites
im sorry for the horrible english.

wait there cool things with these operators they let you set flags with ORing(if im not mistaken) the ORing works like this say if you had some properties that the option of beeing on and off well normal you would have some boolean varible but if you have a group of these you can use ORing to set the property
Like sdl's Init SDL_Init() or better yet window's CreateWindow methods.They can be used for other things in 2d graphics include color keying.

Share this post


Link to post
Share on other sites

void DrawTiles()
{
short i,j;
short MapX, MapY;
short XOff, YOff;

MapX = MapDrawX/32;
MapY = MapDrawY/32;

XOff = MapDrawX & 31;
YOff = MapDrawY & 31;
for(i = 0; i &lt; 16; i++)
{
for(j = 0; i &lt; 21; j++)
{
BlitTile(j * 32 - XOff, i * 32 - YOff, MapX,MapY);
}
}
}

//end of Draw Tiles

void BlitTile(int x, int y, int mapC, int mapR)
{
SDL_Rect Ofs;

Ofs.x = x;
Ofs.y = y;

switch(Map[mapR][mapC])
{
case 0:
SDL_BlitSurface(Grass, NULL, MainScreen, &Ofs);break;
case 1:
SDL_BlitSurface(Rock, NULL,MainScreen, &Ofs);break;
}
}
//end of blittile


thats my code sorry its short so i didnt htink i needed a source thingy... anyways... with this code my screen stays black...and i have to use Ctrl + Alt + Delete in order to get out of it... i know ive been a hassle latley with these questions but im so close! lol thanks alot guy for your time

Share this post


Link to post
Share on other sites
Quote:
Original post by nprz
In that context, you should/could also write
map_xoff = map_drawx % 16;


That would be a deliciously bad idea for performance on embedded systems, where the compilers are generally not smart enough to perform the optimization and operator % takes a long time to compute. In any case, however, a clean comment explaining the operation would be more than welcome.

Share this post


Link to post
Share on other sites
Quote:
Original post by ToohrVyk
Quote:
Original post by nprz
In that context, you should/could also write
map_xoff = map_drawx % 16;


That would be a deliciously bad idea for performance on embedded systems, where the compilers are generally not smart enough to perform the optimization and operator % takes a long time to compute. In any case, however, a clean comment explaining the operation would be more than welcome.


I guess so.
map_xoff = map_drawx & (TILE_SIZE - 1);
would probably be faster, right?

Oh, is
x % y == x & y - 1 (if x & y > 0)?
if so, wouldn't compilers be smart enough to make that optimization?

[Edited by - nprz on January 5, 2006 4:42:21 PM]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!