Conversion to and from a decimal number and a fractional binary number. No limitations on order of magnitude and number of significant digits when the decimal number is supplied as a string. You may optionally set the number of significant bits returned or used in conversion. Requires Java.
Example:
% Make a negative number with 250 significant digits and 150 decimal places
decStr = ['-', regexprep([num2str(randi([0 9], 1, 100)), '.', ...
num2str(randi([0 9], 1, 150))], ' ', '')]
% Get the fractional binary number
binStr = dec2fbin(decStr)
% Convert the binary number back to a decimal number
fbin2dec(binStr)
% A double has 53 significant bits, convert with this limitation
fbin2dec(binStr, 53)
% Compare with MATLAB
str2double(decStr)
引用格式
Patrik Forssén (2024). Unlimited Decimal/Fractional Binary Converter (https://www.mathworks.com/matlabcentral/fileexchange/120878-unlimited-decimal-fractional-binary-converter), MATLAB Central File Exchange. 检索时间: .
MATLAB 版本兼容性
创建方式
R2020a
兼容任何版本
平台兼容性
Windows macOS Linux标签
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Decimal-Binary Converter Version 1.0
版本 | 已发布 | 发行说明 | |
---|---|---|---|
1.0.0 |