Saturday, May 9, 2009

Help needed on C# for negating an integer using bit shift/Two's component?

Hi there,


I have an integer say 30 and i want to make it -30 (minus thirty) but i dont wanna use this :-





int a = 30;


a = a * (-1);





I wanna make use of bit operators .. can any one please help me on this. The code i need is in c#.NET.


Is it so that using the multiplication method (with -1) dosent make any difference, as the final assembly code (CLI) generated for this code will be efficient and take care of this ??


I hope u understood the problem.


Thanks in advance, appriciate you help.





.[]\[].[].[]\[].

Help needed on C# for negating an integer using bit shift/Two's component?
int a=7;


a = ~a;


a++;





That should do it.

bouquet

No comments:

Post a Comment