javascript中的按位左移和右移计算 [英] Bitwise Left shift and Right shift Calculation in javascript

查看:480
本文介绍了javascript中的按位左移和右移计算的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的需要按位计算的帮助。请帮助我,我们的老师要求找到一个简单计算的答案。 (按位)4 << 5,3 >> 3。我们如何在不使用计算机的情况下计算出来。

i really need help with bitwise calculation. plz help me , our teacher asked to find the answer to a simple calculation . (bitwise) 4<<5 , 3>>3 . how do we calculate this without the use of a computer.

编辑1:

还请提及如何执行3& 4和3 | 3

Please also mention how to perform 3 & 4 and 3|3

推荐答案

a<< b = a· 2 b

a >> b = a / 2 b = a· 2 -b (丢弃任何小数)

a << b = a · 2b
a >> b = a / 2b = a · 2-b (dropping any decimals)

所以计算4<< 5,你需要加倍4次5次:4· 2 5 = 4· 32 = 128.同样适用于3 >> 3。

So to calculate 4 << 5, you need to double 4 five times: 4 · 25 = 4 · 32 = 128. Similarly for 3 >> 3.

这篇关于javascript中的按位左移和右移计算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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