Connect with us

Query about Bitwise operations

Discussion in 'Microcontrollers, Programming and IoT' started by alsaf, Nov 14, 2011.

Scroll to continue with content
  1. alsaf

    alsaf

    12
    0
    Oct 2, 2011
    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?
     
  2. Harald Kapp

    Harald Kapp Moderator Moderator

    11,521
    2,654
    Nov 17, 2011
    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
     
  3. alsaf

    alsaf

    12
    0
    Oct 2, 2011
    Thanks for the info Harald, much appreciated.
     
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day

-