Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners bitwise operators
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


buwaneka paranamana
bitwise operators
2 Answer(s)      a year and 7 months ago
Posted in : Java Beginners


include<stdio.h>

int main(){
    short x;
    x=3 | 5; 
    printf("%d \n",x); 
    return 0;
}

why this program give the answer as 7


Advertisement
View Answers

June 1, 2013 at 10:29 AM


hi friend,

Bitwise OR (|) operator returns 1 if either side of operand is 1 else it returns 0 i.e. in this case the bitwise or operator returns 0 (zero) if and only if both side of operand is zero.

So, the binary representation of 3 is = 0011
and the binary representation of 5 is = 0101
When you will apply the or operator    ------
then the binary representation will be  0111 
                                       ------

And the decimal representation of 0111 = 7, that's why your output is given to 7.



June 1, 2013 at 11:04 AM


hi friend,

Please go through the link, may this will be helpful for you

http://www.roseindia.net/java/master-java/java-bitwise-or.shtml



Related Tutorials/Questions & Answers:
bitwise operators
bitwise operators  Write short note on bitwise operators of Java.   Please visit the following links: http://www.roseindia.net/java/java-tips/data/expressions/slides-bitops.shtml http://www.roseindia.net/java/java
bitwise operators
bitwise operators  include<stdio.h> int main(){ short x... this program give the answer as 7  hi friend, Bitwise OR (|) operator returns 1 if either side of operand is 1 else it returns 0 i.e. in this case the bitwise
Advertisements
Bitwise Operators in java 7
In this section you will learn about the Bitwise Operators. This is one type of operators
bitwise operators accept type char as operands
bitwise operators accept type char as operands   Why bitwise operators accept type char as operands
Bitwise and Bit Shift Operators
Bitwise and Bit Shift Operators       In Java the bitwise and bit shift operators are used.... These operators perform bitwise and bit shift operations on integral type
adding two numbers using bitwise operators
adding two numbers using bitwise operators  adding two integer numbers with using bitwise opeators   Hi Friend, Try the following code: public class AddNumberUsingBitwiseOperators { public static void main(String
Java Bitwise Operator
; In computer, the bitwise operators as their name suggests actually work... (or characters). However in Java, the bitwise and bit shift operators are used.... These operators perform bitwise and bit shift operations on integral type
Operators
to a specified type  Bitwise and Bit Shift Operators ~   Unary bitwise... Operators       Operators are symbols that performs some operations on one or more then one operands
Operators
to a specified type  Bitwise and Bit Shift Operators ~   Unary bitwise... Operators       Operators are symbols that performs some operations on one or more then one operands
Java bitwise OR "|" operator
example using Bitwise (OR) "|" operator. public class Operators...Java bitwise OR "|" operator In this section you will learn about how to use" |" operator in java. Java provides six types of operators
Operators
to a specified type  Bitwise and Bit Shift Operators ~   Unary bitwise... Operators       Operators are symbols that performs some operations on one or more than one operands
Operators
to a specified type  Bitwise and Bit Shift Operators ~   Unary bitwise... Operators       Operators are symbols that performs some operations on one or more then one operands
Java Bitwise NOT "~" Operator
Java Bitwise NOT "~" Operator       In this section, you will learn how to use bitwise NOT "~" operator in Java. The Java programming language has operators
Java Bitwise XOR "^" Operator
Java Bitwise XOR "^" Operator       In this section, you will learn how to use bitwise XOR "^" operator in Java. The Java programming language has operators
Operators and Expressions
Bitwise and Bit Shift Operators... Operators and Expressions       Operators: Operators are such symbols that perform some
Java Bitwise AND " &" Operator
bitwise AND " &" operator in Java. The Java programming language has operators that perform bitwise operations. In the example below we have shown... Java Bitwise AND " &" Operator   
ciruit operators.
ciruit operators.  Explain the benefit of short ciruit operators
Java Bitwise OR " |" Operator
Java Bitwise OR " |" Operator       In this section, you will learn how to use bitwise OR "|" operator in Java. The Java programming language has operators that perform
Java XOR operator
Java XOR operator       Java makes available the bitwise operators like AND, OR, XOR, and NOT. .../master-java/java-bitwise-xor.shtml http:/www.roseindia.net/software-tutorials
Java operators
Java operators  What is the difference between the >> and >>> operators
Operators In Java
Operators :   ~ : A unary bitwise complement operator that applied to any...Operators In Java In this section we will read about operators in Java. We will illustrate the use of operators in Java using a simple example. Java
logical operators in objective c
logical operators in objective c  logical operators in objective c
boolean operators in JavaScript
boolean operators in JavaScript  What boolean operators does JavaScript support
SQL AND Operators
SQL AND Operators       The AND operator displays records if both conditions are true. 1st Condition 2nd Condition Result false
SQL OR Operators
SQL OR Operators       The OR operator displays records if any of the conditions is true. 1st Condition 2nd Condition Result false
php Operators
php Operators:       Operators are one of the important feature of every language. In php operators... Assignment Operator Logical Operator String Operator Bitwise Operator Error Control
PHP Bitwise Operator
Learn PHP Bitwise Operator: It is another kind of operator ,called bitwise operator and  supported by PHP. It is so called because instead of operating... it is known as bitwise operator.   Example of PHP Bitwise Operator: <?php
Assignment Operators in java 7
Assignment Operators in java 7 In this section you will learn about the Assignment Operators. This is one type of operators. Assignment Operators... operator. eg. Y>>=3 which shows Y=Y>>3 &= This is Bitwise
 

 

 

DMCA.com