How to get the answer in binary?

2 views (last 30 days)
Shun Weng
Shun Weng on 27 Sep 2015
Answered: Walter Roberson on 27 Sep 2015
Here is the question:
Write a function m-file called to_binary.m that simply converts a single number into a string representing the binary form of that number. You can reuse to_binary.m to calculate the mantissa and exponent + bias terms.
>> to_binary (10.25)
a n s = 1010.01
>> to_binary ( -65)
a n s = -1000001
I know how to convert the number into binary but I don't know how to display them like this : "a n s = -1000001". Please help!

Answers (1)

Walter Roberson
Walter Roberson on 27 Sep 2015
fprintf('a n s = %s\n', TheStringRepresentingTheNumber)

Categories

Find more on Convert Image Type in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!