Shark Deng

Interactive Designer @Shanju Design in Shanghai

touched caffe / mxnet / python / wordpress / bootstrap / Arduino / Raspberry Pi / webgl / three.js / PIXI / 3dMax

Email

Github

逻辑运算

2019-11-19 02:32:33

(一)与&

1 & 1 = 1

1 & 0 = 0

0 & 1 = 0

0 & 0 = 0

例:

1011 1001

1111 0011

——————

1011 0001

物理意义:

工厂总闸和车间分闸同时开,车间机器才有电。

(二)或|

1 | 1 = 1

1 | 0 = 1

0 | 1 = 1

0 | 0 = 0

例:

1010 0001

1001 1011

—————

1011 1011

物理意义:

有两个开关,任意开了房间都能亮。

(三)异或 ^

(四)取反 ~

~1 = 0

~0 = 1

(五)左移 <<

例:

1 = 0000 0001

1 << 0 = 1 = 1*2^0

1 << 1  = 0000 0010 = 2 = 1*2^1

1 << 2 = 0000 0100 = 4 = 1*2^2

1 << 3 = 0000 1000 = 8 = 1*2^3

(六)右移 >>

 

1B = 8b

1KB = 1024B

1MB = 1024KB = 1048576B

1GB = 1024MB

 

(七)原码/反码/补码

正整数的原码、反码、补码完全一样,即符号位固定为0,数值位相同

附:分析2-1=1在计算机内的运算原理(假设机器字长为8位)



——By SharkDeng
如果你喜欢我的文章,欢迎红包赞赏

Leave a Reply

Your email address will not be published. Required fields are marked *