Base-4 arithmetic in MATLAB
Show older comments
Does code already exist for doing Base-4 arithmetic in MATLAB? I find myself needing to average several numbers that are in Base-4, and I am unsure of exactly how to go about doing this. I have seen things like "convert to Base-10, do the math, then convert back", but this really only works if the result of the average is an integer. The thought has occured to me to simply truncate the resulting average (round down), and then convert that back to Base-4, but that seems like I may be inadvertently producing an erroneous average.
I would like to take my Base-4 numbers, add them all up, divide by the number of numbers, and get a resulting Base-4 answer - if this is possible.
Thoughts, suggestions?
2 Comments
James Tursa
on 29 Jul 2017
Why does converting to IEEE double numbers, doing the math, and then converting back not work for you? The average value is the same underlying number, regardless of base and regardless of whether the result is an integer or not. Why do you seem to think otherwise? Can you give a counterexample where this doesn't give the answer you think it should?
John D'Errico
on 29 Jul 2017
The average of two numbers is not dependent on what base they are represented in. Why does it matter if the result is not an integer?
Accepted Answer
More Answers (0)
Categories
Find more on Argument Definitions in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!