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?
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
01 (octal), 0x1 (hexadecimal), 1 (decimal) and 0b1 (binary) is all the same. However, I don't know what kind of number b (11) is. If I guess wrong, the outcome will be very different.
Oh! I thought that "bitter" was refering to the taste, or something harsh / bad. Instead, it means "2 bits". So the numbers must be binary! If they are binary...
(1/2 * 3/2)*2 + (1%2 * 3%2) = 2.5
3 & 1 = 1
So either robtillaart is wrong, or I am wrong. Also, % (modulo) is not regular math.
c = (0 * 1)* 2 + ( 1 * 1) = 0 + 1 = 1 == 01 ==> c = b & a = 01 & 11 = 01
Also, % (modulo) is not regular math.
Since when? What is regular math according to you?
intermezzo regular math? A multiplication is a repeated addition, and an addition is a repeated increment by 1. so in the end everything is repeated an increment by 1 (that sounds like a turing machine!!)
% can be expressed as a subtraction, division and a multiply. a % b = ( a - (a/b)*b)
robtillaart:
What is regular math according to you?
Arithmetic that can be done with a standard calculator. Add, subtract, multiply, divide, square root are the only operations on a standard calculator. Powers are also accepted.
Children are sometimes given dictionaries that miss out all the "rude" words.
Just because your calculator doesn't include all arithmetic operation doesn't mean modulo operations are not members of the set of arithmetic operations.
IF constants are used then the compiler turns either one into 272
IF the values are in variables that may change
A << B is very few cycles, the majority just to put A and B into registers and 1 cycle to shift
A * BC is many cycles
DKL65, you will be far better off just learning bit math than twisting your brain trying to make a few cheap calculator functions do the job.
The Windows calculator can be put into Scientific mode under View, you get many new buttons. There are other free calculators available. For Linux the term more and better comes to mind.
Back in the 80's I had at least 2 "programmer's" hand calculators and one that was a watch.
Print yourself a cheat sheet to refer to. After enough glances/look-ups (which okay may take more than a few weeks if you use it rarely) you won't need it any more.
You can do hex bits with 4 fingers, which are on the table are 1's and which are lifted are zeros. Count 0 to 15 on 4 fingers alone, 0 to 255 with two hands. Not bad when so many people need to take their shoes off to count past 10.
There is a "programmer calculator" on Windows 7 that calculates bitshifts, logic gates, and even convert different types of intergers. I use it all the time. I just asked the question out of curiousity.
AWOL:
Just because your calculator doesn't include all arithmetic operation doesn't mean modulo operations are not members of the set of arithmetic operations.
I didn't say modulo wasn't a legit arithmetic operation (it's actually a useful one); I just said that it wasn't on a standard calculator. When I want to calculate bitmath, I use my brain, or Window 7's Programmer Calculator. I wonder if there are real programmer calculators that people sell.
Most scientific calculators support binary/octal/hex math
currently - realcalc scientific calculator on my android [12 digits in hex mode] - payed version => add your own conversion functions and constants
supports and or xor not nand nor xnor +-*/ sqrt power
before a TANDY EC4014 - 10 digits display + solar was the trigger (still in use)
before a Casio fx-785P - programmable in some basic dialect and it has an IO port (still to be investigated
before another Casio ???
before a slide ruler - Slide rule - Wikipedia - (still have one, not in use)
before a pen and paper (still in use)