allworknoplay Posted February 16, 2009 Share Posted February 16, 2009 Sorry for this dumb math question, but what is the answer to this? $i = 16 << 4; Is $i = 256? I know that the left shift operator multiplies an integer by the powers of two and I have never been great at math... Quote Link to comment Share on other sites More sharing options...
drisate Posted February 16, 2009 Share Posted February 16, 2009 lol you just need to echo $i bro and you will find out hehe echo 16 << 4; Quote Link to comment Share on other sites More sharing options...
allworknoplay Posted February 16, 2009 Author Share Posted February 16, 2009 lol you just need to echo $i bro and you will find out hehe echo 16 << 4; hahaha, I should have tried that, yes it is 256....I just want to make sure I get my facts straight, I'm basically saying, 16 to the power of 2, four times? 16 * 2 = 32 32 * 2 = 64 64 * 2 = 128 128 * 2 = 256 Quote Link to comment Share on other sites More sharing options...
drisate Posted February 16, 2009 Share Posted February 16, 2009 Yeah :-) And you can also use the pow(x,y) function to do that Quote Link to comment Share on other sites More sharing options...
allworknoplay Posted February 16, 2009 Author Share Posted February 16, 2009 Yeah :-) And you can also use the pow(x,y) function to do that When I use that function, I get 65536 instead. "pow(16x4)" VS "16 << 4" So the first one, I think is doing 16x16x16x16 which gives me 65536... The second one is 256... Quote Link to comment Share on other sites More sharing options...
corbin Posted February 16, 2009 Share Posted February 16, 2009 Binary operators operate at a binary level (big surprise). a << x = a * 2^x On a binary level, let's say we have 5: 101 Now << 1 would add a 0 onto the end: 5 << 1 = 1010 = 10 (dec) See how it works? 53 << 7 = 110101 0000000 = 7296 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.