Unlimited Decimal/Fractional Binary Converter

Conversion to and from a decimal number and a fractional binary number. No limitations on order of magnitude/number of significant digits.
6 Downloads
Updated 19 Nov 2022

View License

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)

Cite As

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. Retrieved .

MATLAB Release Compatibility
Created with R2020a
Compatible with any release
Platform Compatibility
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

Version Published Release Notes
1.0.0