Advertisement

binary question

Started by January 21, 2001 10:11 AM
5 comments, last by SKSlayer 23 years, 10 months ago
I have a word what is I want to write a number (let's say 5) but, after the 4th byte 0x0000000000000000 0x000000000000|000 Starting here 0x0000000000101000 To get this ? (It's something with the << or >> operators) Edited by - SKSlayer on January 21, 2001 11:12:34 AM
(you can find me on IRC : #opengl on undernet)
  WORD var;var = 5;var << 3;  



"Yo yo ma"
-Kramer
"Yo yo ma" -Kramer
Advertisement
btw Ox denotes a hexidecimal number

http://members.xoom.com/myBollux
just in case you don''t know, you can use << or >> to multipy or divide numbers by powers of 2 alot faster than normal multuplying or dividing.

ie:

5<<3 == 5*2^3 == 5*8 == 40
7<<4 == 7*2^4 == 7*32 == 224
2>>2 == 2/2^2 == 2/4 == .5 (0 in binary, last bit lost)
6>>0 == 6/2^0 == 6/1 == 6
Chess is played by three people. Two people play the game; the third provides moral support for the pawns. The object of the game is to kill your opponent by flinging captured pieces at his head. Since the only piece that can be killed is a pawn, the two armies agree to meet in a pawn-infested area (or even a pawn shop) and kill as many pawns as possible in the crossfire. If the game goes on for an hour, one player may legally attempt to gouge out the other player's eyes with his King.
Hi smart_idiot,

Modern compilers will optimise that for you anyway, it just serves to make your code a little bit less clear nowdays. Plus they are not limited to powers of 2. i.e. multiplying by 5 will optimise into a left-shift by 2, then adding the original value.

Never underestimate your compiler, it knows all of the tricks, and has (probably) been doing them longer than you

This is still a very useful trick if you write assembly routines though.

Dan

Edited by - danbrown on January 22, 2001 3:43:23 PM

Dan

The compiler (mine anyways) only does that if the number your multiplying is A) constant or will never be changed, and B) is a power of two.
Advertisement
I need to turn on optimization for that to work, and I usually don''t bacause it is slower when I am debugging my programs, the trial and error way.

Oh, and I have been programing since I was about 11, so I have been doing it longer than my current compiler, but I have to admit that it does it faster and better that I ever could.

Besides, who doesn''t like showing off their really cryptic code?
Chess is played by three people. Two people play the game; the third provides moral support for the pawns. The object of the game is to kill your opponent by flinging captured pieces at his head. Since the only piece that can be killed is a pawn, the two armies agree to meet in a pawn-infested area (or even a pawn shop) and kill as many pawns as possible in the crossfire. If the game goes on for an hour, one player may legally attempt to gouge out the other player's eyes with his King.

This topic is closed to new replies.

Advertisement