Conversion of Fractions from Binary to Decimal and Vice Versa
无许可证
The function Fr_bin2dec.m will convert a positive Binary system Fraction to a Decimal system Fraction. The function Fr_dec2bin.m will convert a positive Decimal system Fraction to a Binary system Fraction.
MATLAB itself has bin2dec.m and dec2bin.m, but there seems to be no standard MATLAB function when fractions are involved. For eg, if we wish to quickly obtain the decimal equivalent of the binary fraction : 0.000101, or say, 0.010101111, or say, 11010.1011001 etc. (They are : 0.078125, 0.341796875 and 26.6953125 resp.)
These two dual functions were developed mainly with a view to get quick results while learning Arithmetic (Entropy) Coding in School.(Now, I have added more comments to better explain the programme to other viewers.)
The results of these two functions are limited in accuracy due to the "precision" used in the function num2str.m in addition to Floating Point limits and Rounding errors. These functions have been set to a precision of 16 in the use of num2str.m. Accumulation of errors due to these limits can be seen when the two functions are tested back-to-back in pairs.
Both these files have many "Usage Egs" which will make it easy for the reader to apply these functions and test them with more critical / unique cases of his own - including possibly with some cases which may break the code ? Pl do forward me any new case that breaks the code beyond the aforesaid limitations.
引用格式
Sundar Krishnan (2024). Conversion of Fractions from Binary to Decimal and Vice Versa (https://www.mathworks.com/matlabcentral/fileexchange/5396-conversion-of-fractions-from-binary-to-decimal-and-vice-versa), MATLAB Central File Exchange. 检索时间: .
MATLAB 版本兼容性
平台兼容性
Windows macOS Linux类别
标签
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!版本 | 已发布 | 发行说明 | |
---|---|---|---|
1.0.0.0 |