如何在c#中使用移位运算符进行分割 [英] How to perform dividing using shift operators in c#

查看:79
本文介绍了如何在c#中使用移位运算符进行分割的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的for循环中将这么多的值除以1000,所以这会降低我的程序性能。如何使用移位运算符执行除法?有没有其他解决方案让我知道?

i want to divide the so many values with 1000 in my for loop, so it''s decreasing my programe performance. how can i perform the division with shift operators? Is there any other solutions for this let me know?

推荐答案

硬件已经使用移位运算符进行除法。您还会发现任何名副其实的编译器都会优化您的代码以尽可能使用移位。不幸的是,只有在除以2的幂时才进行换档,因此除以1000会稍微复杂一点。
The hardware already uses shift operators for division. You will also find that any compiler worth the name will optimise your code to use shifts where possible. Unfortunately, shifts only work when dividing by powers of 2, so to divide by 1000 is somewhat more complicated.


这篇关于如何在c#中使用移位运算符进行分割的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆