How to do bitwise shift in c#

  • Thread starter Thread starter love dotnet
  • Start date Start date
L

love dotnet

How do I achive following:
MAKE_HRESULT(sev,fac,code)
((HRESULT) (((unsigned long)(sev)<<31) | ((unsigned long)(fac)<<16)
|((unsigned long)(code))) )
 
love dotnet said:
How do I achive following:
MAKE_HRESULT(sev,fac,code)
((HRESULT) (((unsigned long)(sev)<<31) | ((unsigned long)(fac)<<16)
|((unsigned long)(code))) )

Well I don't know exactly what that's meant to be doing, but you can
bit shift in C# in exactly the same way. For instance:

long result = (((ulong)sev) << 31) | ((ulong)fac)<<16 | (ulong)code;
 
This should work fairly directly, as C# supports shifting in the same manner
as C++.

You will need to switch from "long" to "int", as long in C# is 64 bits.


Something like:

(sev << 31) | (fac << 16) | code

--
Eric Gunnerson

Visit the C# product team at http://www.csharp.net
Eric's blog is at http://blogs.gotdotnet.com/ericgu/

This posting is provided "AS IS" with no warranties, and confers no rights.
 
Back
Top