answersLogoWhite

0


Best Answer

Java's bitwise operators operate on individual bits of integer (int and long) values. If an operand is shorter than an int, it is promoted to int before doing the operations. It helps to know how integers are represented in binary. For example the decimal number 3 is represented as 11 in binary and the decimal number 5 is represented as 101 in binary. Negative integers are store in two's complement form. For example, -4 is 1111 1111 1111 1111 1111 1111 1111 1100. == == & - and

| - or

^ - Xor

~ - not

<< - left shift

>> - right shift

>>> - right shift

Examples:

3 & 5 = 1 (1 if both bits are 1.)

3 | 5 = 7 (1 if either bits are 1) 3^5 = 6 (1 if both bits are different)

~3 = -4 (Inverts the bits)

3 << 2 = 12 (Shifts the bits of n left p positions. Zero bits are shifted into the low-order positions.)

5 >> 2 = 1 (Shifts the bits of n right p positions. If n is a 2's complement signed number, the sign bit is shifted into the high-order positions.)

-4 >>> 28 = 15 (Shifts the bits of n right p positions. Zeros are shifted into the high-order positions.)

{| !

!

!

!

!

|

|}

User Avatar

Wiki User

15y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Explain the bitwise operators available in Java with an example?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

What is the use of Bitwise operators?

AnswerThe bitwise operators treat a number as its binary equivalent rather than as a simple boolean value.For most programming languages, a value of zero is considered FALSE and all other values are TRUEThus, 8 AND 11 returns TRUE as does 3 OR 0In bitwise analysis, each binary bit of the digit are compared. The number of bits compared will depend on the type of number.In C, a CHAR is usually 8 bits and can hold the binary numbers 0 to 255.If we compare 8 (00001000) and 19 (00010011) with bitwise operators, we get different results from Boolean operators:8 BITWISE AND 19 returns 0 (each bit in the response is set to 1 if both equivalent bits compared are 1) but 8 BITWISE OR 19 will return 27.The utility of these methods is in identifying binary data. For example, all files on a PC have the characteristics 'Hidden' 'Read Only' 'Archive' and 'System' which can be set or unset using bitwise operations on a single byte of data. In truth this is a throwback to the days of small memory capacities where saving the odd byte was essential.There are more uses of bitwise, especially in graphics, where XOR can be used to paint a sprite image to display it and then be used again to return a background to its former settings. I regret I lack the skill to explain this better.


Rewrite the BNF of Example 3.4 to add the and -- unary operators of Java?

123


What is operator associativity in C?

OperatorDescriptionAssociativity()[].->++ -- Parentheses (function call) (see Note 1)Brackets (array subscript)Member selection via object nameMember selection via pointerPostfix increment/decrement (see Note 2) left-to-right++ --+ -! ~(type)*&sizeof Prefix increment/decrementUnary plus/minusLogical negation/bitwise complementCast (change type)DereferenceAddressDetermine size in bytes right-to-left * / % Multiplication/division/modulus left-to-right + - Addition/subtraction left-to-right > Bitwise shift left, Bitwise shift right left-to-right < >= Relational less than/less than or equal toRelational greater than/greater than or equal to left-to-right == != Relational is equal to/is not equal to left-to-right & Bitwise AND left-to-right ^ Bitwise exclusive OR left-to-right | Bitwise inclusive OR left-to-right && Logical AND left-to-right Logical OR left-to-right ?: Ternary conditional right-to-left =+= -=*= /=%= &=^= |== AssignmentAddition/subtraction assignmentMultiplication/division assignmentModulus/bitwise AND assignmentBitwise exclusive/inclusive OR assignmentBitwise shift left/right assignment right-to-left ,Comma (separate expressions) left-to-right


Example of relational statements in C programming?

You mean relational operators?if (argc


What is transport operators?

In terms of Air it has to do with which FAA certificate they operate under. For example Part 135 is unscheduled passenger transport.http://www.talonairjets.com

Related questions

What is the use of Bitwise operators?

AnswerThe bitwise operators treat a number as its binary equivalent rather than as a simple boolean value.For most programming languages, a value of zero is considered FALSE and all other values are TRUEThus, 8 AND 11 returns TRUE as does 3 OR 0In bitwise analysis, each binary bit of the digit are compared. The number of bits compared will depend on the type of number.In C, a CHAR is usually 8 bits and can hold the binary numbers 0 to 255.If we compare 8 (00001000) and 19 (00010011) with bitwise operators, we get different results from Boolean operators:8 BITWISE AND 19 returns 0 (each bit in the response is set to 1 if both equivalent bits compared are 1) but 8 BITWISE OR 19 will return 27.The utility of these methods is in identifying binary data. For example, all files on a PC have the characteristics 'Hidden' 'Read Only' 'Archive' and 'System' which can be set or unset using bitwise operations on a single byte of data. In truth this is a throwback to the days of small memory capacities where saving the odd byte was essential.There are more uses of bitwise, especially in graphics, where XOR can be used to paint a sprite image to display it and then be used again to return a background to its former settings. I regret I lack the skill to explain this better.


What are the different types of bit operators Explain with help of example for one bit operator?

The most commonly used ones are AND, OR, XOR (exclusive OR). As an example, if A = 6 (binary 110), and B = 4 (binary 100), the bitwise AND operation will compare each corresponding bit, and result in binary 100 (decimal 4). This can be used to check whether a specific bit, in variable A in this case, is equal to one or zero.


What is the definition of bitwise?

Bitwise operations are those that operate on one or more bits of data, as opposed to larger units of data. For example, in C++, there are the bitwise operators "^" (exclusive or), "&amp;" (and), "|" (or), and "~" (bitwise complement). Using these symbols, it is possible to determine if a bit is set or unset, combine sets of bits, find common bits, or invert all the bits at once. This allows the use of a single field (such as an int variable) to hold multiple pieces of data. Algorithms that concern themselves with saving space, such as compression algorithms, embedded system code, and so on, will often use bitfields instead of entire bytes of data whenever practical.


Explain with example how charts are used in analysis Also explain the different types of charts available in Excel?

"http://wiki.answers.com/Q/Explain_with_example_how_charts_are_used_in_analysis_Also_explain_the_different_types_of_charts_available_in_Excel"


What is a Yamazumi Chart?

A Yamazumi chart is essentially a stacked bar chart which displays the balance of cycle times between a set of operators, for example on an assembly line. There are free templates available online.


What are the operators used in C describe with example?

Operators used in c areBinary operatorAirthematic operatorlogical operatorRelational operatorBitwise operatorUnary operatorTernary operator


Where can someone learn about Boolean operators?

Boolean operators are words that are used to define the relationship between other words. For example, both AND and OR are considered Boolean operators. More in depth information can be found in advanced grammatical texts.


Rewrite the BNF of Example 3.4 to add the and -- unary operators of Java?

123


What is an operators and its statements?

For example '+' is an operator, and its operands are the values (expressions) on its two sides, example: 3*3 + 4*4


What is operator associativity in C?

OperatorDescriptionAssociativity()[].->++ -- Parentheses (function call) (see Note 1)Brackets (array subscript)Member selection via object nameMember selection via pointerPostfix increment/decrement (see Note 2) left-to-right++ --+ -! ~(type)*&sizeof Prefix increment/decrementUnary plus/minusLogical negation/bitwise complementCast (change type)DereferenceAddressDetermine size in bytes right-to-left * / % Multiplication/division/modulus left-to-right + - Addition/subtraction left-to-right > Bitwise shift left, Bitwise shift right left-to-right < >= Relational less than/less than or equal toRelational greater than/greater than or equal to left-to-right == != Relational is equal to/is not equal to left-to-right & Bitwise AND left-to-right ^ Bitwise exclusive OR left-to-right | Bitwise inclusive OR left-to-right && Logical AND left-to-right Logical OR left-to-right ?: Ternary conditional right-to-left =+= -=*= /=%= &=^= |== AssignmentAddition/subtraction assignmentMultiplication/division assignmentModulus/bitwise AND assignmentBitwise exclusive/inclusive OR assignmentBitwise shift left/right assignment right-to-left ,Comma (separate expressions) left-to-right


What do you men by precipitation explain by giving an example?

what do u mean by precipitation? explain by giving an example


What are conditional connectives. Explain with an example?

What are conditional connectives? Explain use of conditional connectives with an example