Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

What are bitwise operators in C used for ?

Status
Not open for further replies.

saudrehman

Member level 1
Joined
Dec 20, 2005
Messages
41
Helped
1
Reputation
2
Reaction score
0
Trophy points
1,286
Activity points
1,713
bitwise operators in C

can anybody explain the use of Bitwise operators like and,or,exor in C programming for microcontrollers.
 

member_tdh

Member level 5
Joined
Feb 6, 2006
Messages
86
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Activity points
2,187
Re: bitwise operators in C

you can read it in book programming for C.
Exp: "and"
1&1=1
1&0=0
0&1=0
0&0=0
 

philba

Full Member level 2
Joined
Jan 26, 2006
Messages
132
Helped
13
Reputation
26
Reaction score
1
Trophy points
1,298
Activity points
3,102
bitwise operators in C

note that when you bitwise and (or, xor), each bit is anded (ored, xored) with the correspoding bit in the other word.

so 0b1010 & 0b1100 becomes 0b1000
or in hex 0xA & 0xC becomes 0x8

and is great for masking/clearing bits - say you want to zero all but the last three bits in a byte, call it val.
val = val & 0x7;

or is good for setting bits. for example, setting pins to input (1) or output (0):
TRISB = TRISB | 0b00011100; // sets pins 2, 3 & 4 to input, leave the others alone

I prefer to use binary repersentation when fiddling with bits in registers. makes it alot clear what's going on.

Phil
 

eng_ahmed22

Full Member level 4
Joined
Jun 7, 2005
Messages
190
Helped
20
Reputation
40
Reaction score
5
Trophy points
1,298
Activity points
2,944
Re: bitwise operators in C

hi
this may help u

Bitwise Operators:

Operators that work on the individual bits within a variable are
called bitwise operators. Following is a table of all of these operators:

& bitwise AND
| bitwise Inclusive OR
^ bitwise Exclusive OR
~ one’s complement.
>> right shift
<< left shift

more details u can find in any c book
the forum EDA E-books Upload/Download has many c books, just search

salam
Ahmed
www.i-g.org
 

shanmugavel

Newbie level 6
Joined
Sep 8, 2005
Messages
13
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
india, bangalore
Activity points
1,369
Re: bitwise operators in C

i need a help on the same bitwise operations.
but this a little complicated. this is bitwise copying and pasting.

i need to copy a particular number of bits and paste at different loaction.
eg., A stream has 1000 bits. i am copying from 102 bit to 201 bit, then pasting(overwriting) at 305 th bit. is there an algorithm to do this.
regards,
shanmugavel
 

coshkun

Full Member level 2
Joined
Aug 27, 2005
Messages
126
Helped
18
Reputation
36
Reaction score
10
Trophy points
1,298
Activity points
2,214
Re: bitwise operators in C

shanmugavel this is totally different subject.First we need to know how your 1000 bit stream is organized in the memory?
 

Ivan-Holm

Member level 5
Joined
Jun 3, 2010
Messages
84
Helped
3
Reputation
6
Reaction score
2
Trophy points
1,288
Location
Denmark
Activity points
1,894
hi if I wont to write 0b 00001010 to a memmery that holds 0bxxxx0000 and I dont wont to overwrite "x" data on the memmery and I don't know wot these x binary holds. how do I do? i C programming
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top