Base-4 arithmetic in MATLAB
古いコメントを表示
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 件のコメント
James Tursa
2017 年 7 月 29 日
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
2017 年 7 月 29 日
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?
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Argument Definitions についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!