-3

I understand what bitwise operations are, and I know how to use them in my code. However, are there situations where the processor will automatically use bitwise operations to perform a computation? For example, are there arithmetic operations which, when invoked, will cause the processor to internally use bitwise operations without my explicitly using them in code?

3
  • 1
    Please rephraise the question because what you want to know is not clear.
    – Ramhound
    Apr 21, 2014 at 18:51
  • I rephraised the question.
    – Acaz Souza
    Apr 21, 2014 at 19:46
  • This is still really hard to understand
    – Ramhound
    Apr 21, 2014 at 22:04

2 Answers 2

2

Examples would be multiplication and division. Moving the bits to the left for one position is a multiplication with 2, moving them right for one position is a division by 2. It is faster for a processor to do the bit moving than calculating.

1
  • Don't forget modulo (%) a power of two, which can use and.
    – user180742
    Apr 22, 2014 at 13:48
0

It's going to be processor dependent but I'd guess usually none unless specifically called by your code. If your code is anything but assembly, then this will usually depend on the compiler. You can see a long discussion on this here: https://stackoverflow.com/questions/235072/do-modern-compilers-optimize-the-x-2-operation-to-x-1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .