0
Explanation on Bitwise Operators ?
^
13 Réponses
+ 3
Start from here, links to details on each operator is available in "See also" section.
https://www.sololearn.com/learn/4070/?ref=app
+ 1
Ipang Jayakrishna🇮🇳 I get it that these operators perform actions on the binary format of integers.
But what for? For example:
00000110
&
00001100
=
00000100
What is it good for? What does it give me back?
+ 1
00000110 = 6
&
00001100 =12
=
00000100 = 4
6&12=4 is the operation here.
If you are asking what are the uses of bitwise operation.., then those are very faster than other operations because it directly deals with bits by processor.
For ex: finding odd even of a number ,
number&1 result 0 for even number ,1 for odd numbers
This operstion is much efficient
than num%2 (result=>0 for even, 1 for 0dd.)
+ 1
+ 1
00000110 = 6
&
00001100 =12
=
00000100 = 4
For & (bit wise And) operation truth table is
0 & 0 = 0
0 & 1 = 0
1 & 0 = 0
1 & 1 = 1
Apply these on every single bit of 2 numbers in respecting positions as you do in normal addition.
( taking count for only 4 bits )
0000 0110 = 6 &
0000 1100 =12
=
0000 0100 = 4
Note : ex: for 12
Bits positions for 12
8th 7th 6th 5th 4th 3rd 2nd 1st :
0 0 0 0 1 1 0 0 = 12
(a=6, b =12, works like
nth bit of a & nth bit of b.
for First bit 0 & 0 = 0
2nd 1 & 0 = 0
3rd 1 & 1 = 1
4th 0 & 1 = 0
5th 0 & 0 = 0
6th 0 & 0 = 0
7th 0 & 0 = 0
8th 0 & 0 = 0
(update)
So final result is 00000100 = 4
hope it clear.?
edit:
Yahel updated.
+ 1
For all the common use cases of bitwise operators, please check
https://code.sololearn.com/cvOWut2HJNHW/?ref=app
0
https://www.sololearn.com/learn/4074/?ref=app
you can find all bitwise operators with this link (previous and next) ( see "more about")
0
Jayakrishna🇮🇳 my question is: how is 6&12 = 4 ? What kind of operation is it? (+, -, *, /, %)
0
Jayakrishna🇮🇳 why do you take only the last 4 digits? Because an integer consists of only 4 bits?
0
Yahel
No. Remainings bits are 0 value all. So 0&0=0 for all. So I skipped in explanation. There it counts 8bit, or 16 bit, or 32bits, ..... operations.... depends on processor.
edit :
now updated check again..
0
0
bitwise operators are the root operations that can be handle at a cpu very low level... all instructions of a cpu are only done with combination of bitwise operations (electronic gates / transistors: two bits inputs => one bit output)... integrated circuits (cpu) can accomodate 100 million or more transistors ^^
0
To eliminate branching