Well.. because.
For &
, the AND
operator:
0001 = 1
0100 = 4
---- (AND)
0000 = 0
for |
, the OR
operator:
0001 = 1
0100 = 4
---- (OR)
0101 = 5
Bitwise & => If both bits are higher, then the output is higher else output is zero.
0 0 1
1 0 0
-----
0 0 0 => 0 // 1 & 1 = 1 , 1 & 0 = 0
Now try yourself Bitwise |
. Any of the bit is higher, output is higher.
1
是0b001
,和4
是0b100
,那么,自然, 1&4
是0b000
和1|4
是0b101
,这是5
。
Look at it in binary form.
1d(ecimal) = 001b(inary)
4d(ecimal) = 100b(inary)
thus
001b
100b & (both bits have to be 1 to yield 1)
--
000b = 0d
and
001b
100b | (only one on either side (or both) has to be 1 to yield 1)
--
101b = 5d
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.