Go Down

Topic: Convert bitmath into regular math? (Read 1 time) previous topic - next topic

dkl65

Jun 11, 2012, 03:15 am Last Edit: Jun 11, 2012, 05:04 pm by dkl65 Reason: 1
Hello!
I was wondering if bitmath (bitshift left, bitshift right, OR, XOR, AND, NOT) and modulo can be expressed using regular math (add, subtract, multiply, divide). I know that NOT in regular math is (-x)-1. How about the other bitwise operations?

Is the symbol ` and $ ever used in Arduino? What is it used for?

Thanks!

Delta_G

Bitshift left and right are multiplication and division by powers of 2.


GoForSmoke

The bitmath is generally more efficient and never that I know of less so.

I find it harder to express logic in English than in Code.
Sometimes an example says more than many times as many words.

WizenedEE

In bash, the backtick (`) means "execute this and replace with stdout" but it's depreciated (the $(command) is preferred).

robtillaart

Quote
I was wondering if bitmath (bitshift left, bitshift right, OR, XOR, AND, NOT) can be expressed using regular math

I think that in theory all can be expressed in regular math but the complexity involved would explode for some operations. (Never tried / investigated disclaimer :)
I even think you need to hold state in between

the bitshifts are easy, as is the NOT, However to express an AND in normal math would include isolation of individual bits by using powers of 2 for every bit to isolate them and then multiply the bits on the same position and add the results.

for a 2 bitter the formula involved 4 divisions and 1 multiply - and that is the easiest but 1

a= 01
b= 11
c = (a/2 * b/2)*2 + (a%2 * b%2); // c = b & a

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Go Up