Bitwise AND Operator:
Between the most extensively utilised conceptual bitwise operations is this a person. The “&” is a solitary uppercase symbol applied to denote it. On either conclude of the (&) operator, there are two integer statements. When each bits have a little bit 1, the final result of a bitwise AND operate is 1 conversely, the result is . The AND operation has been cleared from the graphic down below. You can see when both x and y are 1, the consequence is also 1. On the other hand, if 1 of them is 1 and the other is , the end result is .
Let us get commenced and see some examples of Bitwise AND (&) operator in C language. At the time of this article’s execution, we used the Ubuntu 20.04 Linux functioning technique. Make absolutely sure you have a “gcc” compiler mounted on your Linux program to compile your C code. If not, use the next command:
Let’s have our very first illustration of elaborating the operating of AND operator in C language. Soon after the login from the Ubuntu Linux process, you have to open up the Terminal shell to produce a new C form file. SO, use “Ctrl+Alt+T” to start it speedily. Or else, you can navigate in direction of the exercise area on the desktop of your Linux technique. Soon after the look for bar has been opened, generate “terminal” and hit Enter. A pop-up software will be opened. Faucet on it to launch it. Now the Terminal shell has been opened, let us make a new C-style file employing the contact command in the shell as shown underneath. We have offered the name “exam.c” to the C file:
Now, the file has been designed. You can see the newly created file in your property listing of the Ubuntu 20.04 Linux running method. You can open the file “test.c” applying the GNU Nano editor command as below in the terminal. Publish the following command and push Enter:
Now, the test.c file has been produced in the GNU Nano editor. Produce the underneath appended C script in it. This code comprises the enter-output regular library header. The most important purpose has been utilized to do the working. The initial printf statement is just made use of to simply just exhibit a Welcome information. In the future line, we have stated two integer-form variables. The worth of the variable “x” is larger than that of the variable “y“. Yet another print assertion has been used to declare the consequence of AND operator on both the variables “x” and “y”. Following that, the main perform closes. Preserve your Nano file working with the “Ctrl+S” crucial and navigate to the terminal shell once more via the “Ctrl+X” important.
Let us 1st appear at the little bit values of each the integers “x” and “y”. When we utilize the AND operator on the little bit values of each the variables “x” and “y”, it displayed “000000”, which is the little bit worth of . This usually means our response need to be after the application of AND operator.
Let’s compile the C code at the terminal applying the “gcc” compiler and the title of a file, appended below:
Now the code has been compiled, let us operate it using the “output” command under. You can see it displays as the outcome of AND operator on 36 and 16 following the Welcome information:
Let us have a different instance of hunting at the working of AND operator on some integer values. Open the exact same “examination.c” file using the terminal by means of the nano editor down below:
Let us update the file “test.c” with the subsequent code. Right after introducing the enter and output standard stream in the file, we have made use of the “main” process with the return type as integer. We have included a printf assertion to print the “welcome” information. Yet another integer style variable, “z”, has been declared with a worth of . We have used the AND operator on the two the variables and additional the end result of AND operator in the variable “z”. The last printf assertion has been printing the saved consequence of the AND operator employing the variable “z”. Help save your code and abandon the nano editor by way of “Ctrl+S” and “Ctrl+X” accordingly.
You can see the little bit values of both the integers “50” and “17”. The calculated consequence of AND operator on equally the bit values of “50” and “17” exhibits that the outcome will be 16. Allow see if it is suitable.
Compile your code very first by way of the “gcc” compiler:
Execute the take a look at.c file making use of the output command as underneath. You can see that the end result is as similar as we expected, e.g., 16:
Let us have our very last example to see the doing the job of AND operator in the C language. Open up the file “check.c” as soon as all over again making use of the nano editor in the shell:
Paste the similar code in your file beneath to update it. Once again, making use of the enter and output regular header library in our code, we have made use of the principal strategy with the integer return variety. This time we have utilised the two integers but switched the position of smaller sized and greatest values. Print assertion has been used to utilize the & operator and display screen the consequence:
The bit consequence of making use of AND on equally the little bit values of integers is 2.
Compile your code when once again with the gcc compiler:
After compilation of code, simply operate the output execution command to see the benefits. The end result is the similar as we have mentioned earlier mentioned, e.g., 2.
In this short article, you have seen the illustrations of implementing AND operator or integer values and how it will work on little bit values. We hope this short article has served you at its ideal and you don’t need to have even more guidance on this subject.