FreewareFire Posted July 26, 2003 Posted July 26, 2003 Please have a look here, http://www.xtremedotnettalk.com/t74824/s.html - Sorry, don't know where to post this thread!? Quote
reanjr Posted July 26, 2003 Posted July 26, 2003 Try something along the lines of i = (i << 1) | (i >> 31); Quote
reanjr Posted July 26, 2003 Posted July 26, 2003 /* This should work. I tried it in VB real quick, but not C# Should be a lot quicker than the other version as well Warning: may have problem with signed integers I don't know how .NET treats them on bit shifts */ val = (val << 1) | (val >> 31); Quote
FreewareFire Posted July 26, 2003 Author Posted July 26, 2003 I've found this... #define ROTR(x,y,b) (((x)>>(y&((b)-1))) | ((x)<<((b)-(y&((b)-1))))) it's for C++ could someone translate it to C# ? x is value, y how many rotates and b how many bits the value has... Thx isn't there a simplier way? I'm really confused! Quote
OnErr0r Posted July 26, 2003 Posted July 26, 2003 I'm very new to C#, but what if you created a generic function like this: uint RolRight(uint x, byte y, byte b) // number, shift, bits { //#define ROTR(x,y,b) (((x)>>(y&((b)-1))) | ((x)<<((b)-(y&((b)-1))))) return (x >> (y & (b - 1))) | (x << (b - (y & (b - 1)))); } And called it like one of these: byte Ret = (byte)RolRight(0x81, 1, 8); ushort Ret = (ushort)RolRight(0x8001, 1, 16); uint Ret = RolRight(0x80000001, 1, 32); Quote
FreewareFire Posted July 26, 2003 Author Posted July 26, 2003 This one looks very good! I will try it! Thank you!!! Quote
FreewareFire Posted July 29, 2003 Author Posted July 29, 2003 I forget to tell anyone: It works great!!!! Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.