你曾经不得不使用位在实际项目转移? [英] Have you ever had to use bit shifting in real projects?

查看:127
本文介绍了你曾经不得不使用位在实际项目转移?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你有过使用位移在实际编程项目?大部分(如果不是全部)高级语言有移位运算符在其中,但是当你实际上需要使用它们?

Have you ever had to use bit shifting in real programming projects? Most (if not all) high level languages have shift operators in them, but when would you actually need to use them?

推荐答案

我还是写code为没有在硬件浮点支持系统。在这些系统中你需要一点移几乎所有的运算。

I still write code for systems that do not have floating point support in hardware. In these systems you need bit-shifting for nearly all your arithmetic.

你也需要转移到生成散列。多项式算法(CRC,里德 - 所罗门codeS是主流应用程序)或使用变化为好。

Also you need shifts to generate hashes. Polynomial arithmetic (CRC, Reed-Solomon Codes are the mainstream applications) or uses shifts as well.

然而,只用变化,因为它们是得心应手,前preSS笔者预期的到底是什么。你可以模拟所有位的变化与乘法,如果你想要,但是这将是更难写,难读,有时慢。

However, shifts are just used because they are handy and express exactly what the writer intended. You can emulate all bit-shifts with multiplication if you want to, but that would be harder to write, less readable and sometimes slower.

编译器检测,其中乘法可以减少到一个移位的情况。

The compilers detect cases where multiplication can be reduced to a shift.

这篇关于你曾经不得不使用位在实际项目转移?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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