IndiaBIX.com
Arithmetic Aptitude Data Interpretation
Logical Reasoning Verbal Reasoning Non Verbal Reasoning
General Knowledge
Sudoku Number puzzles Missing letters puzzles Logical puzzles Playing cards puzzles Clock puzzles
C Programming C++ Programming C# Programming Java Programming
Microbiology Biochemistry Biotechnology Biochemical Engineering
Civil Engineering Mechanical Engineering Chemical Engineering Networking Database Questions Computer Science Basic Electronics Digital Electronics Electronic Devices Circuit Simulation Electrical Enigneering Engineering Mechanics Technical Drawing
Placement Papers Group Disucssion HR Interview Technical Interview Body Language
Aptitude Test Verbal Ability Test Verbal Reasoning Test Logical Reasoning Test C Programming Test Java Programming Test Data Interpretation Test General Knowledge Test
Data Structures Operating Systems Networking DATABASE Database Basics SQL Server Basics SQL Server Advanced SQL Server 2008 JAVA Core Java Java Basics Advanced Java UNIX Unix File Management Unix Memory Management Unix Process Managemnt C Interview Questions The C Language Basics .NET Interview Questions .NET Framework ADO.NET ASP.NET Software Testing

C Programming - Bitwise Operators - Discussion

@ : Home > C Programming > Bitwise Operators > General Questions - Discussion

Read more:

"Success has many fathers, while failure is an orphan."
- (Proverb)
2. 

Which bitwise operator is suitable for turning off a particular bit in a number?

[A]. && operator[B]. & operator
[C]. || operator[D]. ! operator

Answer: Option A

Explanation:

No answer description available for this question.


Ravi(Bit Mesra Cse_2K7) said: (Thu, Oct 21, 2010 12:03:39 AM)    
 
Any bit AND(&) with 0 will give a zero .i.e. will turn that particular bit OFF.

Suhas . U said: (Fri, Nov 26, 2010 11:07:31 AM)    
 
Which bit u want make 0 ...make only that bit 0 n allother bits 1...
ex:-to make 3rd bit 0 use &operator with one operand as11110111

Arjun Prasad said: (Mon, Feb 28, 2011 08:15:33 AM)    
 
To make above operand you take a number 1 and then shift its only set bit to the number of the bit you want to turn off(1<<3) and then take AND with given number.

Arjun Prasad said: (Mon, Feb 28, 2011 08:18:20 AM)    
 
~(1<<"bit position") is the operand

Sohan Lal Mits Gwalior said: (Tue, Mar 1, 2011 09:25:40 AM)    
 
Bitwise 'AND' of any bit with zero bit is always zero (off).

Kumar said: (Sat, Apr 23, 2011 10:26:30 PM)    
 
Could anyone give an explanation in brief with example the above examples could not be understood

Sundar said: (Sun, Apr 24, 2011 08:01:55 AM)    
 
@Kumar

Let me explain.

How to turn off only the 4th bit (from right) in a 16-bit binary number?

unsigned int intFalg4Off = 0xfff7;
//Hex = 0xfff7 (or) Decimal = 65527 (or) Binay = 11111111 11110111

unsigned int intInputVal = 255;
//Decimal = 255 (or) 0x00ff (or) 00000000 11111111

unsigned int Result = intInputVal & intFalg4Off;

The result will be the & (AND operation) between the binary numbers given below :

11111111 11110111
00000000 11111111
00000000 11110111 (Decimal = 247 or Hex = 0x00f7)

Here 4th bit of the given input has been turned off. Therefore, intResult will contain the value 247.

Hope this will help you. Have a nice day!

Ramya said: (Fri, Jul 8, 2011 11:41:41 AM)    
 
Thanks sundar.

Anuradha Sharma said: (Fri, Sep 2, 2011 05:46:06 PM)    
 
If we take any bit AND (&) with 0 will give a zero. (i.e) Will turn that particular bit OFF.

Saurav said: (Mon, Sep 5, 2011 12:26:55 AM)    
 
But! why will && not work?

Heena said: (Fri, Sep 16, 2011 11:08:01 PM)    
 
Because && is a logical operator not a bitwise (bitwise is a operator that takes single bit at a time).

Bari said: (Thu, Sep 22, 2011 08:05:55 PM)    
 
Please explain about bitwise operator?

Bari said: (Thu, Sep 22, 2011 08:08:14 PM)    
 
How to work bitwise ?

Vinod Basi said: (Fri, Nov 4, 2011 10:01:33 PM)    
 
Sorry, I know this is an outdated thread... But just saw Mr.Gaurav's doubt to be one which I had a days back.
Here is a simple explanation, correct me if am wrong.

@Saurav

Its like && and || are logical operators, evaluting true statements.
Eg:
Sachin && Sehwag opens batting, It returns true(1) only if both the guys are present to open the game. Else False(0)

Sachin || Sehwag, return true(1), if either Sachin or Sehwag accompanied by someone else opens the game. Else false(0)

& and | are bitwise operators, High and Low
AND, OR gates truth table pretty much explains it.
Eg:
2 & 3 (AND)
010
&
011
------
010

2 | 3 (OR)
010
|
011
------
011

Bitwise operators can be predominantely found in Embedded design, to find the status (ON or OFF) of a bit in a system.


Hope this explains...

Cheers...

Athi said: (Tue, Nov 29, 2011 08:44:18 AM)    
 
I have 1 doubt please tell me how to find the status of a bit ie char s[50];

Then write a c program to find the status of 170th bit.

Satyaprakash said: (Thu, Jan 12, 2012 11:52:47 AM)    
 
Turn off operator in bitwise operators is and because it turns 1&0 and 0&1 into turn off(that is o). |(OR) bitwise turns preceeded operations into turn on(that is 1).

Hence AND IS turn off operator.

Naveen Kumar Ramisetty said: (Thu, Feb 2, 2012 11:18:12 PM)    
 
Thanks ramya.

Deepanwita said: (Thu, Jul 26, 2012 10:42:48 PM)    
 
Bitwise operator is more easily been applied than the logical operator.

Mouni said: (Mon, Sep 3, 2012 11:30:59 AM)    
 
Please explain how to convert hexa decimal into binary.

Saiprabha said: (Fri, Sep 7, 2012 11:17:05 AM)    
 
If you want to off the bit means u want to make it ZERO it is possible in only & condition because
in & if 1 1 o/p-1
else 0

Dinesh said: (Tue, Sep 18, 2012 02:42:24 PM)    
 
I explain in simple manner

bit wise & truth table
=========================
a b z
=========================
0 0 0
1 0 0
1 1 1
0 1 0
==========================
only one condition satisfyied foe on bit excpt bit value is off position

Prema Latha.S said: (Fri, Sep 28, 2012 09:15:42 PM)    
 
Bitwise AND operator (&), one's complement operator(~)

Example: To unset the 4th bit of byte_data or to turn off a particular bit in a number.

Explanation: Consider, Material from Interview Mantra. Subscribe to free updates via email.

char byte_data= 0b00010111;byte_data= (byte_data)&(~(1<<4));

1 can be represented in binary as 0b00000001 = (1<<4)

<< is a left bit shift operator,

It shifts the bit 1 by 4 places towards left.

(1<<4) becomes 0b00010000

And ~ is the one's complement operator in C language.

So ~(1<<4) = complement of 0b00010000

= 0b11101111

Replacing value of byte_data and ~(1<<4) in (byte_data)&(~(1<<4));

We get (0b00010111) & (0b11101111)

Perform AND operation to below bytes.

00010111

11101111

-----------

00000111

-----------

Thus the 4th bit is unset.

Write your comments here:
Name *:     Email:


© 2008-2013 by IndiaBIX™ Technologies. All Rights Reserved | Copyright | Terms of Use & Privacy Policy

Contact us: info@indiabix.com     Follow us on twitter!