Not look at the next type of operators bitwise operators as the name implies bitwise operators work 2
with individual bits of our prince an opening it can be either in digit primitives or bullion bullion 3
is operant is very rarely used also discussing I maybe corporators be discussed about something called 4
or put in promotion rule that are put in smaller than aned are automatically promoted. 5
And that also applies here for bitwise operators. 6
Also note is that we said bitwise operators book at Bigler. 7
But then we are also saying that operands can be integers what that means is because operators would 8
actually consider the binary representation of indigent operands and then operate on them at big limit 9
vivants only a few examples. 10
When looking at each of the operators before you look at the operators before you discuss that because 11
operators are mostly used one to they're heavily used is an embedded system applications which work 12
in resource constrained environments for example in such environments you may have to work with very 13
limited memory and such a guest thinks has to be manipulated very efficiently and because operators 14
can play an important role here. 15
They're also typically used in hospitals and if you don't know what a hostel is just don't worry it 16
will be covered later. 17
But it's a fundamental data structure like NRD on in Java there is a data structure called hash map 18
which we will also study later. 19
It is basically a hostage implementation and dentally. 20
It does make use of couple of bitwise operators It seems bitwise operators are also heavily used in 21
data compression and data encryption fuse generally speaking there is a good chance that you may never 22
use because operators unless you are doing some really low level programming work where performance 23
is critical and things have to be managed very efficiently. 24
But let's learn how backwards operators work and in case you happen to work on projects that need bitwise 25
operations then you will know how to make use of them. 26
Adhere to the forbit operators bitwise and bitwise OR bit was exclusive you are and it was not. 27
Let's not look at each of them fosters because an operator like logical and operator big words and also 28
use an impersonal symbol Howard because I use this only as single and percent because I know Peter would 29
written one if bought and put Sarwan let's just consider an example where x is an NY study playing with 30
words and on x and y will return an integer value of 1 and to see how. 31
Let's consider the binary representations of x and y. 32
On here the first one is for X. Well second one represents. 33
As you can see only the last bit of both number one. 34
And so in the output only the last bet would be one and the rest would be zero. 35
So the result is that decimal value of an operations or brilliance instead of integers then all bitwise 36
operators would create the boolean value grew as one and font size zero. 37
So just keep that in mind as the examples we discuss here will only deal with integers next is because 38
autopen are to like logical art because are also used as a pipe symbol but it uses on the single pipe 39
because Oddworld read and one if one off the end put Mrs. Van you know one example where X is one on 40
Y U Street playing big boys or on x and y will read the entry and to see how. 41
Let's once again consider the binary representations of x and y. 42
As you can see we have one in the output if one off the and put this one. 43
So the result is the decimal value three next is big exclusive OR operator but you got it's a moot because 44
exclusives are written so one if only one of the puppets is one that is even if both and put bits out 45
of one then it would still return to zero. 46
And that's the main difference between bitwise exclusive or on bitwise OR you know one example where 47
X is one on y history applying bitwise exclusive or on x and y will return a value off to adhere to 48
the binary representations as you can see we have one in the output only if one of the input bits is 49
fine but not what the last bits are. 50
One for both numbers and the corresponding output bit to 0 so the final result is not dissimilar value 51
to next is Bidvest not operator which is a unity operator and it certainly doesn't mean bitwise NOT 52
simply in which bits affects operant let's consider that one example where X has been I'm applying bitwise 53
was not on X will return a value of minus two and to see how let's consider the binary representation 54
of x as you can see all zeroes are made ones. 55
And the last bit one is made zero under deserting binary number corresponds to the entire minus two 56
if you recall we discussed a book short so good operators logical and unlogical are among big operators 57
big ones and big ones are are also referred to as non-charter so good operators that is there are no 58
short girls as in the case of short circuit operators. 59
This means that these operators forced JVM to always check both the options so far because on the right 60
operand is evaluated even if left operand evaluates to force. 61
Similarly for bitwise aren't right operand is evaluated even if left operand this rule nobody discussing 62
it maybe cooperators will look at something called crampon or it might be an assignment operators which 63
provided a short and elegant syntax bitwise operators also have similar notation it is going to Bishan 64
involving because I know her first one shows that expanded form. 65
Well the second one shows a shorter comp on assignment operator and here is an example of a boolean 66
variable be initialized with the value of true and the second statement is a read initialization of 67
the same variable b so basically a big rise I kind of grew on fault is being done here which will return 68
a value of funds. 69
Similar pompon operators are also going for it because our and words exclusive operators finally let's 70
look at a quick demo. 71
A new method called bitwise operators has been added to basics demo class which can be downloaded from 72
the resources section. 73
Let's look at the program now. 74
This is the new method bitwise operators. 75
And here we are going to demonstrate a few things. 76
One as big as operators I played on Intimidator pipes and the big guys and they played on Boullion operand 77
and big wigs are played on Kadek our parents. 78
I'm finally a big raise or played on doubletake or like which should not compile because because I'll 79
put it as can be applied only on integers or boolean operations. 80
Let's just go ahead and compile and exit this. 81
We need to be in the basics directory 82
. 83
And here is the output. 84
So the first four lines demonstrate the bit was all but it does applied on integer data types. 85
I'm not going to discuss this as these examples are the exact same examples that we have seen earlier 86
where X is one on y history. 87
And here are the different bitwise operators applied on them bitwise and or exclusive or are not. 88
So we are not going to discuss that. 89
And the next one is a bit wise or because I and I play it cue and false Richard and so false then a 90
bit odd is applied on characters that are types and the characters are even be here since there are 91
characters. 92
They get promoted done in sort of corresponding values have ninety seven and ninety eight and so that 93
binary representation so taken on a bitwise OR is applied on them. 94
So there is only really been ninety nine Next let's see the big words are applied on the database. 95
And we know that this should not be compiled. 96
So but let's do component exuded this 97
and it is there it says that bag open and types for binary operator it only works with integers and 98
boolean operations and that's the end of our discussion on bitwise operators.