Deathheadmoth
Limp Gawd
- Joined
- Aug 23, 2001
- Messages
- 288
Hi, I have a question about something I've never seen used before in C or C++..
If you do this:
int test = (3<<2);
And then cout test, you get 12.
What does that mean? I've never seen << used in defining a variable.
Also, if you do this:
int test = (3<<2) | (5<<1);
You get 15.
Again, I'm not following what's happening. What is | doing?
The reason I'm asking is because I saw someone try to define an IP address as this:
long IP = ((155<<24)|(246<<16)|(14<<8)|11);
I know an IP address is 32 bits, so it seems like its storing the 155 in the first 8 bits, 246 in the second, and so on.. but how does this actually work? What do the operators mean?
I tried googling this stuff, but it's not a very easy thing to google
Thanks in advance for your help.
If you do this:
int test = (3<<2);
And then cout test, you get 12.
What does that mean? I've never seen << used in defining a variable.
Also, if you do this:
int test = (3<<2) | (5<<1);
You get 15.
Again, I'm not following what's happening. What is | doing?
The reason I'm asking is because I saw someone try to define an IP address as this:
long IP = ((155<<24)|(246<<16)|(14<<8)|11);
I know an IP address is 32 bits, so it seems like its storing the 155 in the first 8 bits, 246 in the second, and so on.. but how does this actually work? What do the operators mean?
I tried googling this stuff, but it's not a very easy thing to google
Thanks in advance for your help.