0% found this document useful (0 votes)
28 views

Java

1. The document is a report submitted by Sahand Rebwar Qadr to his professor Mr. Mahdi Mohammed Younis on the topic of bitwise operators in Java. 2. It discusses the different types of bitwise operators in Java including AND, OR, XOR operators. It provides examples of how each operator functions when applied to binary numbers. 3. The report concludes that logical operators like AND, OR, and XOR allow programmers to combine conditional expressions and control program execution flow based on evaluating multiple conditions using these bitwise logical operators.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views

Java

1. The document is a report submitted by Sahand Rebwar Qadr to his professor Mr. Mahdi Mohammed Younis on the topic of bitwise operators in Java. 2. It discusses the different types of bitwise operators in Java including AND, OR, XOR operators. It provides examples of how each operator functions when applied to binary numbers. 3. The report concludes that logical operators like AND, OR, and XOR allow programmers to combine conditional expressions and control program execution flow based on evaluating multiple conditions using these bitwise logical operators.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 14

University of Sulaimani

College of Commerce

Information Technology Department

1st Stage – 1st Semester

Subject: Fundamental Of Programming


Bitwise Operator In Java

Submitted By

Sahand Rebwar Qadr

Supervised by
Mr. Mahdi Mohammed Younis

Submission Date: 5 JAN 2023


2023 2722
Table of Content

Bitwise operator in java..............................................................................................2

1.What is Operator:.................................................................................................2

2.type in operator:..................................................................................................3

3.Bitwise operator:..................................................................................................3

4.Introduction to Bitwise Operators in Java:...........................................................4

5.Types of Java Bitwise Operators in Java:..............................................................5

6.Bitwise logical:......................................................................................................5

6.1 And operator (&):..............................................................................................6

6.2 OR Operator (||):..............................................................................................7

CONCLUSION...............................................................................................................8

REFERENCES................................................................................................................9

2|Page
Bitwise operator in java

1.What is Operator:
Operators are used for a variety of purposes in Java. Arithmetic operators are used for
performing basic arithmetic operations such as addition, subtraction, multiplication, and
division. Logical operators are used to compare the values of two variables and make
decisions based on the outcome. Relational operators are used to compare two values and
determine their relationship. The bitwise operators are a special type of operator used to
manipulate the individual bits of a given number. They are used to perform bit-level
operations such as AND, OR, XOR, and NOT, which are essential when working with binary
numbers. Bitwise operators are also used to shift bits to the left or right to create a new value.
By using these operators, Java developers can manipulate data more efficiently and
effectively.

2.type in operator:
1. Arithmetic Operators
2. Unary Operators
3. Assignment Operator
4. Relational Operators
5. Logical Operators
6. Ternary Operator
7. Bitwise Operators
8. Shift Operators

3.Bitwise operator:
Bitwise operators are one among those operators which perform their tasks at
binary level directly on binary digits (also known as bits), the smallest form of data
in a computer, or its data types. These bitwise operators are faster and an efficient

3|Page
way to interact with computers to make heavy computation in a linear time
because it works directly within memory rather than through a level of abstraction
of software.

These bitwise operators alter data in constant time complexity and function parallelly by
making it efficient on all systems, and therefore this process of altering data through bitwise
operators is termed Bit Manipulation. Almost all programming languages will have to work
with data abstractions (for eg, objects or variables), rather than the bits they represent.
However, direct bit manipulation is required to optimize the performance of code and
reduce errors in numerous scenarios. (atul, 2022)

Here are few examples of tasks that require bit manipulation or knowledge of Bitwise
Operators:

 Low-level device control


 Error detection and correction algorithms
 Data compression
 Encryption algorithms
 Optimization

We shall explore bitwise operators in java throughout this article in detail with its
implementation.

4.Introduction to Bitwise Operators in Java:

You can see how many steps are reduced with bit manipulation from normal representation.

4|Page
Bit Manipulation is performed using Bitwise Operators, on each and every bit of a number
individually and can be used with any data types such as int, float, short, char, etc.

Bitwise operators work on a binary equivalent of decimal numbers i.e. the operation is
performed on decimal numbers and internally these operators work on individual bits bit by
bit, as per the given operations:

 First, the operands are converted to their binary representation


 Next, the operator is applied to each binary number and the result is calculated
 Finally, the result is converted back to its decimal representation

Normal arithmetic operators perform operations on human-readable values (3+4), while


bitwise operators manipulate the low-level data directly. (atul, 2022)

5.Types of Java Bitwise Operators in Java:

Type in operator in java

5|Page
6.Bitwise logical:
Sometimes, whether a statement is executed is determined by a
combination of several conditions. you can use logical operators to
combine these conditions. Logical operators are known as Boolean
operators or bitwise logical operators. The boolean operator
operates on boolean values to create a new boolean value. The
bitwise logical operators are “&”, “|”, “^”, and “~” or “!”. The
following table shows the outcome of each operation.

6.1 And operator (&):


Syntax - cond1 && cond2

This operator is named as the Logical AND operator. This operator returns true when both
conditions under evaluation are true, otherwise it returns false.

Short-Circuiting Effect: If the first condition cond1 evaluates to false, it doesn't carry out
a check on the second condition. It returns false without evaluating the second condition.

We are going to understand the above-mentioned definition with the help of a table that
shows us the results of the conditions in which this operator has been used. The table
represents the using of AND operator.

6|Page
From the table above, we can see that the AND operator returns true only if both conditions
(under consideration) are true. Even if one of the conditions is false, the AND operator
returns false.

Example

output

7|Page
Explanation:

 In the code above, we are finding the maximum number out of p, q, r (taken as inputs).
 If p is maximum among p, q, and r variables then both condition p > q and p > r should
be satisfied. Thus we have combined these two conditions using the AND (&&) operator.
 Similar logic is employed for q. If p and q are not maximum, the maximum is obviously r.

6.2 OR Operator (||):


Syntax - cond1 || cond2

This operator is named as the Logical OR operator. This operator returns true if any one of
the given conditions is true. OR operator returns false if and only if both conditions under
evaluation are false.

Short-Circuiting Effect: This operator doesn’t check the second condition if the first one
is true. The second condition is checked only and only if the first condition is false.

Let’s see a table for this blog too.

8|Page
It is clear from the table above that OR operator returns false if and only if both
conditions are false. Otherwise, it returns true.

Example

9|Page
Output

6.3 Xor Operator (^):


Syntax - ^
This is a bitwise operator and stands for "exclusive or". It performs logical
operations as well if the operands are boolean variables.

10 | P a g e
From the table above, it is clear that when both the inputs are identical, false is
returned. However, if XOR is performed on opposite operands, true is returned.

example

11 | P a g e
Output

12 | P a g e
CONCLUSION
As a class of operators, logical operators enable us to combine several conditional expressions.

In Java, there are three different kinds of logical operators:

Operators AND (&&) OR (||)

Operator NOT (!

We can manage a program's execution flow with the use of logical operators.

When both conditions being evaluated are true, the AND operator yields true; otherwise, it returns
false.

If any of the predetermined conditions is true, the OR operator returns true. Only when both
conditions being evaluated are false does the OR

operator yield false.

The NOT operator takes a single value as input and outputs the value's inverse. Unlike the AND
and OR operators, this one is a unary operator.

In the event that both inputs are identical, XOR returns false.

13 | P a g e
REFERENCES

Difference between Hardware and Software - GeeksforGeeks. (n.d.). Retrieved December 10,
2022, from https://www.geeksforgeeks.org/difference-between-hardware-and-software/

What is Computer Hardware and Software with Examples? (n.d.). Retrieved December 10, 2022,
from https://www.chtips.com/computer-fundamentals/what-is-computer-hardware-and-
software/

What Are the Differences Between Hardware and Software? (n.d.). Retrieved December 10, 2022,
from https://www.computerhope.com/issues/ch000039.htm

Differences between Hardware and Software | Hardware vs Software - javatpoint. (n.d.). Retrieved
December 10, 2022, from https://www.javatpoint.com/hardware-vs-software

CPU vs. RAM: Understanding the Differences - History-Computer. (n.d.). Retrieved December 10,
2022, from https://history-computer.com/cpu-vs-ram/

RAM vs. Processor—Which Is More Important to Your Business? (n.d.). Retrieved December 10,
2022, from https://www.intel.com/content/www/us/en/business/small-business/resources/ram-
vs-processor.html

14 | P a g e

You might also like