0

Explanation on Bitwise Operators ?

^

4th Jul 2021, 11:06 AM
Yahel
Yahel - avatar
13 Antworten
+ 3
Start from here, links to details on each operator is available in "See also" section. https://www.sololearn.com/learn/4070/?ref=app
4th Jul 2021, 11:08 AM
Ipang
+ 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?
4th Jul 2021, 11:16 AM
Yahel
Yahel - avatar
+ 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.)
4th Jul 2021, 11:35 AM
Jayakrishna 🇮🇳
4th Jul 2021, 11:37 AM
Jayakrishna 🇮🇳
+ 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.
4th Jul 2021, 11:49 AM
Jayakrishna 🇮🇳
+ 1
For all the common use cases of bitwise operators, please check https://code.sololearn.com/cvOWut2HJNHW/?ref=app
4th Jul 2021, 3:42 PM
Calviղ
Calviղ - avatar
0
https://www.sololearn.com/learn/4074/?ref=app you can find all bitwise operators with this link (previous and next) ( see "more about")
4th Jul 2021, 11:08 AM
Jayakrishna 🇮🇳
0
Jayakrishna🇮🇳 my question is: how is 6&12 = 4 ? What kind of operation is it? (+, -, *, /, %)
4th Jul 2021, 11:40 AM
Yahel
Yahel - avatar
0
Jayakrishna🇮🇳 why do you take only the last 4 digits? Because an integer consists of only 4 bits?
4th Jul 2021, 12:20 PM
Yahel
Yahel - avatar
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..
4th Jul 2021, 12:26 PM
Jayakrishna 🇮🇳
4th Jul 2021, 12:33 PM
Yahel
Yahel - avatar
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 ^^
4th Jul 2021, 3:52 PM
visph
visph - avatar
0
To eliminate branching
4th Jul 2021, 5:01 PM
Pemadam