Jump to content
• Advertisement

Public Group

# Whats this symbol?

This topic is 4611 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

##### Share on other sites
Advertisement
It's the bitwise and.

Link

#### Share this post

##### Share on other sites
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-expressionand-expression & equality-expression The bitwise AND operator (&) compares each bit of the first operand to thecorresponding bit of the second operand. If both bits are 1, the correspondingresult 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 usualarithmetic conversions covered in Arithmetic Conversions, are applied to theoperands. Operator Keyword for & The bitand operator is the text equivalent of &. There are two ways to accessthe bitand operator in your programs: include the header file iso646.h, orcompile 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

##### Share on other sites
sheesh bits and stuff... i never got to that kinda thing.. looks kinda crazy lol but thanks.. ide rate you but i wont do much help.

#### Share this 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

##### 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

##### 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 Tilesvoid 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

##### Share on other sites
hmm okay i think i fixed it.... thanks anyways!

#### Share this post

##### Share on other sites
Quote:
 Original post by nprzIn that context, you should/could also writemap_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

##### Share on other sites
Quote:
Original post by ToohrVyk
Quote:
 Original post by nprzIn that context, you should/could also writemap_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

##### Share on other sites

• Advertisement
• Advertisement

• ### Popular Contributors

1. 1
2. 2
JoeJ
20
3. 3
frob
17
4. 4
5. 5
• Advertisement

• 10
• 10
• 11
• 13
• 9
• ### Forum Statistics

• Total Topics
632197
• Total Posts
3004728

×

## Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!