移位的实际应用 [英] Practical applications of bit shifting

查看:62
本文介绍了移位的实际应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我完全理解如何移位位.我已经在纸上和代码中处理了许多示例,并且在那里不需要任何帮助.

I totally understand how to shift bits. I've worked through numerous examples on paper and in code and don't need any help there.

我正在尝试提出一些实际的例子,说明如何使用位移.以下是一些我想出的例子:

I'm trying to come up with some real world examples of how bit shifting is used. Here are some examples I've been able to come up with:

  • 也许我能概念化的最重要的例子与字节序有关.在大字节序系统中,最低有效位从左开始存储,而在小字节序系统中,最低有效位从右开始存储.我想对于使用相反字节序策略的系统之间的文件和网络传输,必须进行某些转换.

  • Perhaps the most important example I could conceptualize had to do with endianness. In big endian systems, least significant bits are stored from the left, and in little endian systems, least significant bits are stored from the right. I imagine that for files and networking transmissions between systems which use opposite endian strategies, certain conversions must be made.

在处理n ^ 2,n ^ 4等任何乘法时,编译器和处理器似乎可以进行某些优化.这些位只是向左移动. (相反,我想同样适用于除法,n/2,n/4等).

It seems certain optimizations could be made by compilers and processors when dealing with any multiplications that are n^2, n^4, etc. The bits are just being shifted to the left. (Conversly, I suppose the same would apply for division, n/2, n/4, etc.)

在加密算法中.即使用一系列的移位,反转和组合来混淆某些东西.

In encryption algorithms. Ie using a series of bit shifts, reverses and combinations to obfuscate something.

所有这些准确的例子吗?您有什么要补充的吗?我花了很多时间学习如何实现移位/重新排序/字节交换,我想知道如何将其实际应用=)

Are all of these accurate examples? Is there anything you would add? I've spent quite a bit of time learning about how to implement bit shifting / reordering / byte swapping and I want to know how it can be practically applied = )

推荐答案

我不同意最重要的示例是字节顺序,但这很有用.您的示例是有效的.

I would not agree that the most important example is endianness but it is useful. Your examples are valid.

哈希函数通常使用位移来获得混乱的行为.与您的加密算法没什么不同.

Hash functions often use bitshifts as a way to get a chaotic behavior; not dissimilar to your cryptographic algorithms.

这篇关于移位的实际应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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