PDA

View Full Version : Fun Facts, collect :>



kung foo man
19th August 2013, 06:38
If you shift a number with $number<<20, it's multiplied by 1024*1024. That's useful to convert MB into Bytes:



megabytes = 256;
bytes = megabytes << 20;

woodchop146
19th August 2013, 16:47
Your explanation is kinda bad.
Are you just trying to say that the operator << 20 will multiply by 1024?

kung foo man
20th August 2013, 00:26
Bytes into Kilobytes:
256 << 10 == 256 * 1024
Bytes into Megabytes:
256 << 20 == 256 * 1024 * 1024


One shift to left is "multiplied by 2", so 10 shifts are 2^10 = 1024, which is the "byte to kilobyte" formula... no clue if that's understandable now xD

woodchop146
20th August 2013, 00:57
Just gonna clear up Kung's failure:
1 << 1 returns 2
1 << 2 returns 4
1 << 3 returns 8

As you can see the number you set after the << is relative to how far into a binary sequence you are.
0:1
1:2
2:4
3:8
4:16
5:32
6:64

If you can't find the pattern then you have so very much to learn.

woodchop146
20th August 2013, 19:49
In addition:
400
Rather basic but you can google for other pages, pretty much teaches you all of basic C++(syntax and keywords).