converting floating numbers to binary and set the result in a matrix form

8 views (last 30 days)
Hi,
Lets suppose we have a simple matrix x = [6.01179008584765e-08 6.45966692516766e-08 1.34123895886390e-07 ; 6.01179008584670e-08 6.45966692516663e-08 1.34123895886373e-07]
Question 1: I want to convert each floating number to binary and set the value of each in a matrix so the result should look like this:
x1=[1st binary value 2ed binary value ; 3ed binary value 4th binary value] >> in matrix form
*Notice the semicolon separating the first row and the second row
Question 2: should I convert the numbers to decimal first than to binary? if so, is there a function to convert floating point numbers to decimal? (built in function?)
  3 Comments
Abdullah Zamil
Abdullah Zamil on 31 Jan 2015
Edited: Abdullah Zamil on 31 Jan 2015
it's a project am working with a friend.
I've tried a float2bin() however, the result shows in one vector but i don't want it in one vector. I want it in an array of 2x2 since my example consist of 2x2 matrix.
btw the example is random
Image Analyst
Image Analyst on 31 Jan 2015
I don't have float2bin() - it's not a function in base MATLAB or any of my toolboxes so I can't help you with that. I asked 3 questions (homework, data type, and difference) and you didn't answer a single one. So good luck with this. Someone else will probably guess what you mean, and attempt an answer, but I don't know what to do.

Sign in to comment.

Accepted Answer

Guillaume
Guillaume on 31 Jan 2015
I don't know how your float2bin works, but I assume it uses typecast to change the numbers from double to uint64 without modifying the underlying bit representation. typecast can indeed only deal with vectors. Once data is uint64, you can just use dec2bin to get the binary representation as string. It is trivial to reshape your output with reshape:
x = [6.01179008584765e-08 6.45966692516766e-08 1.34123895886390e-07
6.01179008584670e-08 6.45966692516663e-08 1.34123895886373e-07];
b = dec2bin(typecast(x(:), 'uint64'), 64);
b = reshape(num2cell(b, 2), size(x))
It all seems a bit pointless though. Why do you care about the binary representation of doubles?

More Answers (0)

Community Treasure Hunt

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

Start Hunting!