Maker Pro
Maker Pro

Query about Bitwise operations

alsaf

Oct 2, 2011
12
Joined
Oct 2, 2011
Messages
12
I had come heard of Bitwise but I didn't really understood it until recently when I had being learning Assembly language programming. While I understood its principles and how it worked, I didn't really know what purpose it was for. From research the some purposes are bit fields/flags and arithmetic.

I would assume, in terms of embedded programming, using bitwise operations for arithmetic purposes would be better than built-in ones when doing heavy number crunching operations but would it be beneficial or even noticeable if any occasional calculations were required?
 

Harald Kapp

Moderator
Moderator
Nov 17, 2011
13,728
Joined
Nov 17, 2011
Messages
13,728
Hi alsaf,
bitwise operations are not for arithmetic purposes, although one could use them in that way.

There are several uses for bitwise operations. Just afe to mention:
1) store lot of data with little memory. E.g. ona an 8 Bit computer, an 8 bit data word could be used to store the presence or absence of 8 different properties. Bit n=1 could mean property "n" is present, Bit n=0 could mean property "n" is missing. To set, clear and check single bits, you need bitwise operations. In this example you need only 1 data word instead of 8 words to store this infiormation.
2) set, clear and check single port bits of a microcontroller. A microcontrollers I/Os are very often grouped in words of 8, 16 or 32 bits. You need bitwise operations e.g. to set a singel I/O line to high or low or to check its status.

You will find more usefull information especially on bitwise operations in maicrocontroller manuals.

Regards,

Harald
 
Top