Bitwise Shift (Opcodes)? 
Author Message
 Bitwise Shift (Opcodes)?

Can anyone provide me with an example of using the opcodes shl and shr?  I
have been trying without much success - mainly a syntactical problem (I
think).  From my understanding, this should be called like below:

ILGenerator.Emit(shr, <INT32, 64, etc..>)

Or, if this is not the best method for doing a bitwise shift in vb.net,
point me in another direction?

Thank you!

Rob



Tue, 28 Dec 2004 08:09:56 GMT  
 Bitwise Shift (Opcodes)?
Rob,

Quote:
>Can anyone provide me with an example of using the opcodes shl and shr?  I
>have been trying without much success - mainly a syntactical problem (I
>think).  From my understanding, this should be called like below:

>ILGenerator.Emit(shr, <INT32, 64, etc..>)

YourILGenerator.Emit(OpCodes.Shr)

Shr pops two integers (value and bit count to shift) off the stack and
pushes the result.

Quote:
>Or, if this is not the best method for doing a bitwise shift in vb.net,
>point me in another direction?

I don't know what you consider "best", but it would be a lot easier to
use simple division in VB, or put the shifting code in a C# library.

Mattias

===
Mattias Sj?gren (VB MVP)

http://www.msjogren.net/dotnet/



Tue, 28 Dec 2004 09:44:51 GMT  
 Bitwise Shift (Opcodes)?
Looks like I will go with division.  I wanted to try and avoid creating a
DLL just for this one method .. and I think I am still a little green to
tackle building the information needed by the ILGenerator (can't figure it
out :) ).

Does utilizing division over the ILGenerator slow down the code execution
considerably? (some articles I read hinted that using division was rather
slow).

Once again Mattias, thank you for taking time to help!

Robert


Quote:
> Rob,

> >Can anyone provide me with an example of using the opcodes shl and shr?
I
> >have been trying without much success - mainly a syntactical problem (I
> >think).  From my understanding, this should be called like below:

> >ILGenerator.Emit(shr, <INT32, 64, etc..>)

> YourILGenerator.Emit(OpCodes.Shr)

> Shr pops two integers (value and bit count to shift) off the stack and
> pushes the result.

> >Or, if this is not the best method for doing a bitwise shift in vb.net,
> >point me in another direction?

> I don't know what you consider "best", but it would be a lot easier to
> use simple division in VB, or put the shifting code in a C# library.

> Mattias

> ===
> Mattias Sj?gren (VB MVP)

> http://www.msjogren.net/dotnet/



Tue, 28 Dec 2004 10:56:36 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Bitwise Operators for Shift Left or Shift Right

2. Bitwise shift operation

3. bitwise shift

4. Bitwise shifting question

5. Bitwise Shift

6. bitwise shift in VB

7. Bitwise Shift Operation?

8. Does VBScript have bitwise shift operators?

9. what are bitwise shift operators in VB?

10. How to perform a bitwise left shift

11. Bitwise shifting

12. Is there a bitwise shift operator

 

 
Powered by phpBB® Forum Software