There is currently no direct relationship between the number of commands executed and the number of cpu cycles that are needed to execute them. You also believe that the operator in C # corresponds to one build command / cpu, which is also incorrect.
Your code looks right, as described in the description of your algorithm (note that long signed, use ulong for unsigned behavior).
If you want to use specialized cpu extensions (for example, mmx, sse, whatever) that can perform add-shift in one instruction, you need to use assembly code. But I'm not sure if such a specific instruction exists. This may depend on the type of processor you have.
You cannot use assembler code directly with C #, but you can use assembly with c (either as using a linked object, or making it an inline assembly). Compiled c code can be used from C # /. NET with interoperability .
But the first and important question for you: What are you trying to accomplish?
I doubt that performance is very important for your application, and even if you should honestly ask yourself if C # is the best language for your purpose.
source share