bitwise operators

bitwise operators

include<stdio.h>

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

why this program give the answer as 7

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
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 OR "|" operator
Java bitwise OR "|" operator In this section you will learn about how to use" |" operator in java. Java provides six types of operators...; operator in Java: A simple example using Bitwise (OR) "|" operator
ModuleNotFoundError: No module named 'bitwise'
ModuleNotFoundError: No module named 'bitwise'  Hi, My Python... 'bitwise' How to remove the ModuleNotFoundError: No module named 'bitwise... to install padas library. You can install bitwise python with following command
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
) Operators 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 Operators List
Java Operators List  What are the Java operators, please explain and share the Java operator list.   Java Operators List Any Java beginner can easily get confused with the types of Java operators and it can also
Java Operators List
Java Operators List  What are the Java operators, please explain and share the Java operator list.   Java Operators List Any Java beginner can easily get confused with the types of Java operators and it can also
Java Operators List
Java Operators List  What are the Java operators, please explain and share the Java operator list.   Java Operators List Any Java beginner can easily get confused with the types of Java operators and it can also
Java Operators List
Java Operators List  What are the Java operators, please explain and share the Java operator list.   Java Operators List Any Java beginner can easily get confused with the types of Java operators and it can also
Java Operators List
Java Operators List  What are the Java operators, please explain and share the Java operator list.   Java Operators List Any Java beginner can easily get confused with the types of Java operators and it can also
Java operators
Java operators  What is the difference between the >> and >>> operators
Java XOR operator
Java XOR operator       Java makes available the bitwise operators like AND, OR, XOR, and NOT. ...:/www.roseindia.net/java/master-java/java-bitwise-xor.shtml http:/www.roseindia.net/software
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
boolean operators in JavaScript
boolean operators in JavaScript  What boolean operators does JavaScript support
logical operators in objective c
logical operators in objective c  logical operators in objective c
operators
operators
operators
php Operators
php Operators:       Operators are one of the important feature of every language. In php operators... Operator Assignment Operator Logical Operator String Operator Bitwise Operator
PHP Bitwise Operator
Learn PHP Bitwise Operator: It is another kind of operator ,called bitwise... number, that's why it is known as bitwise operator.   Example of PHP Bitwise Operator:ADS_TO_REPLACE_3 <?php $a=10; $b=2;ADS_TO_REPLACE_4
SQL OR Operators
SQL OR Operators       The OR operator displays records if any of the conditions is true. 1st Condition 2nd Condition Result false
Arithmetic Operators in java 7
In this section you will learn about the Arithmetic operators. This is one type of operators
Unary Operators in java 7
In this section you will learn about the Unary operators. This is one type of operators
SQL AND Operators
SQL AND Operators       The AND operator displays records if both conditions are true. 1st Condition 2nd Condition Result false
What is the difference between the >> and >>> operators?
What is the difference between the >> and >>> operators?   hi, What is the difference between the >> and >>> operators? Thanks
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...;= This is Bitwise AND assignment operator eg. Y&=3 which shows Y=Y&3ADS_TO
PHP Operators
Operators in PHP: Every computer language has its own set of operators, most of the operators are same among all languages and  few languages supports some different set of operators. PHP supports mainly three kind of operators
PHP Operators
3.5. PHP Operators Operators are used for performing specific tasks. The operators in PHP are same like other programming languages like Arithmetic operators, Assignment Operators, Comparison Operators, and logical operators. 3.5.1.
difference between == and === operators?
difference between == and === operators?  Is (====) operator available in java or not? difference between
precedence operators c++ example
precedence operators c++ example  What is the precedence of operators in c++ and how does it works?   This might be helpful.. Operator precedence
Operators in java 7
This tutorial describes the concept of operators in java 7
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
left shift and rigth shift operators
left shift and rigth shift operators   hi some programs for left shift and right shift operators
Arithmetic Operators
Arithmetic Operators Operator is used to perform operation on variable and values. Arithmetic Operators is used to perform arithmetic operations(like... the list of available arithmetic operators : OPERATOR WORK USE
ModuleNotFoundError: No module named 'simplicial-operators'
ModuleNotFoundError: No module named 'simplicial-operators'  Hi...: No module named 'simplicial-operators' How to remove the ModuleNotFoundError: No module named 'simplicial-operators' error? Thanks   Hi
ModuleNotFoundError: No module named 'time-operators'
ModuleNotFoundError: No module named 'time-operators'  Hi, My... named 'time-operators' How to remove the ModuleNotFoundError: No module named 'time-operators' error? Thanks   Hi, In your python

Ads