Author Topic: I have an idea. (Hacking)  (Read 11567 times)

Bosola

  • Fire hazard!
  • *
  • Posts: 1752
    • View Profile
    • My YouTube Channel
Re: I have an idea. (Hacking)
« Reply #25 on: 2011-04-11 20:58:32 »
A left / right shift (also known as a logical shift) is when you 'move' the contents of a number to the right or left.

For instance, if I take the binary number 00111100, and left shift it by two places, I get 11110000 - the 1111 is moved two places to the left. If I left shift it by four places, I get 1111000000.

The right shift is slightly different. When I right shift, digits 'fall off' the 'end' of the number. For example, if I right shift 00111100 by two places, I get 00001111. If I right shift it by four places, I get 00000011.

In effect, a left shift multiplies, and a right shift divides by powers of two. If I take the binary number 10 (=2), and left shift it by 1, I get 100 (4). Thus, left shifting by X places is the same as multiplying by 2 to the power of X. Right shifting is the same, but for division.

What's significant is that left and right shifts are far faster to perform than multiplication and division. On most CPUs, division is horrendously slow, so compilers will usually swap any division by a power of two with an appropriate logical right-shift. This makes your application faster.

Wutai Clan

  • *
  • Posts: 115
    • View Profile
Re: I have an idea. (Hacking)
« Reply #26 on: 2011-04-12 02:40:36 »
Thanks for the explanation, I think I understand now. :)

Honestly, it's a pitiful thing for a programmer to admit, but, alas, math is my biggest weakness, so you lost me a bit here..

Quote
If I take the binary number 10 (=2), and left shift it by 1, I get 100 (4). Thus, left shifting by X places is the same as multiplying by 2 to the power of X.

But the rest made sense, I pick up programming stuff fairly quick, math, takes a bit longer to sink in. Though, I guess as long as I remember its for(faster) div\sub, I should be fine.
« Last Edit: 2011-04-12 03:01:01 by Wutai Clan »

Wutai Clan

  • *
  • Posts: 115
    • View Profile
Re: I have an idea. (Hacking)
« Reply #27 on: 2011-04-13 09:52:28 »
.....
« Last Edit: 2011-04-13 20:21:14 by Wutai Clan »

Bosola

  • Fire hazard!
  • *
  • Posts: 1752
    • View Profile
    • My YouTube Channel
Re: I have an idea. (Hacking)
« Reply #28 on: 2011-04-13 16:51:01 »
Can't GCC accept inline ASM for x86?

Wutai Clan

  • *
  • Posts: 115
    • View Profile
Re: I have an idea. (Hacking)
« Reply #29 on: 2011-04-13 17:28:45 »
Created a project.. Moved there..
« Last Edit: 2011-04-14 08:37:08 by Wutai Clan »

Bosola

  • Fire hazard!
  • *
  • Posts: 1752
    • View Profile
    • My YouTube Channel
Re: I have an idea. (Hacking)
« Reply #30 on: 2011-04-15 12:48:05 »
In that case, I will close this thread.

If, in future, anyone would like to resume theoretical discussion of this subject in this thread, please PM me.