所谓“两个位"是什么意思?使用按位运算符时 [英] What is meant by "both bits" when using bitwise operators

查看:102
本文介绍了所谓“两个位"是什么意思?使用按位运算符时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

W3Schools页面将按位AND描述为:

This W3Schools page describes bitwise AND as:

如果两个位均为1,则将每个位设置为1.

Sets each bit to 1 if both bits are 1.

并给出一个示例:

5&1返回1,与0101&0001返回1.

5 & 1 returns 1, same as 0101 & 0001 returns 1.

据我所知,0101是4位,而0001是另外4位.那么,如果两个位都为1"是什么意思?他们在说些什么?

As far as I know, 0101 are 4 bits and 0001 are another 4 bits. So, what is meant by "if both bits are 1"? What are these bits they are talking about?

推荐答案

按位操作就是按位操作,每个位进入CPU并与另一位组合.

A bitwise operation is exactly bitwise, each bit goes into the CPU and gets combined with another bit.

因此,0001 AND 0101,根据该公式计算四个输出位中的每个位.如果左侧操作数中位置1的位与右侧操作数中位置1的位均为1,则输出将获得位置1上设置的位.

So 0001 AND 0101, each of the four output bits are calculated according to that formula. If bit on position 1 in the left operand AND bit on position 1 in the right operand are both 1, the output gets the bit set on position 1.

功能更强大的CPU可以并行计算许多这些操作,64位CPU可以并行执行64位等.在您的示例中,要并行计算要计算4位.

A stronger CPU can calculate many of these operations in parallel, a 64-bit CPU can do 64 bits in parallel etc. In your example, 4 bits as to be calculated in parallel.

(然后将这些操作在CPU中组合起来,以在ALU中进行其他算术运算,在CPU的不同部分中锁存TCM中的数据位,等等.)

(Then these operations are combined in the CPU to du other arithmetic operations in the ALU, latching databits in a TCM etc in different parts of the CPU.)

这篇关于所谓“两个位"是什么意思?使用按位运算符时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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