Developer community
0 votes
65 views
asked by Guru (24.6k points) 30 54 84 | 65 views

1 Answer

0 votes
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,

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.
answered by Guru (39.1k points) 10 22 36

Related questions

0 votes
1 answer
asked by keem Expert (13.2k points) 27 43 61 | 33.5k views
0 votes
1 answer
asked by daniel Advisor (5.6k points) 1 7 14 | 63 views
0 votes
1 answer
asked by rajesh Guru (39.1k points) 10 22 36 | 23 views
Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true

Categories


C Books Guide and List
C++ Books Guide and List
Best Java Books

3.8k questions

4k answers

117 comments

10.7k users

3,751 questions
4,046 answers
117 comments
10,709 users