Is there anyway to convert a number to binary without using dec2bin?

24 次查看(过去 30 天)
Dear everyone
I want to convert these values to binary without using dec2bin
why I do not want dec2bin because for each value the result will be 8 bits this maximize the numbers of values and I want these number 21 values no more no less
in the same way that im2bw work I did it but the result are all ones
Here are the values 77.152,128.35,136.04,191.57,222.5,241.67,254.83,272.7,251.13,286.17,310.83,305.48,303.8,301.91,318.85,365.8,350.72,301.91,220.91,145.37,94.304
Here are the values after applying dec2bin(The problem: the number of values is very huge and I want it 21 values like the Original values) 0,0,0,0,0,0,0,1,0,1,1,1,1,1,1,1,1,1,0,0,0,0,1,1,1,1,1,1,0,1,0,0,0,0,0,0,0,0,0,1,1,0,1,0,0,0,1,1,1,0,1,0,0,0,0,0,0,1,1,0,1,0,1,0,0,0,1,0,1,1,0,1,0,1,1,1,1,1,1,0,1,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,0,0,1,0,1,0,1,1,1,1,0,1,1,1,0,1,0,1,1,0,0,1,1,1,1,1,1,1,0,1,1,0,0,1,1,0,1,0,0,1,1,0,1,1,1,1,1,1,1,0,1,0,0,0,1,1,0,1,0,1,1,1,0,1,0,1,0,1,0,0,0,1,1,0,0,1,0,1,0,0,1,0,0,1,1,1,0,1,0,1,0,1,0
Here are the values after applying im2bw(The problem:all the values are ones and I do not want that )
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
Please,give me answers?
  3 个评论
Ameligege
Ameligege 2015-4-6
I am looking for result like im2bw .This mean for each number represented by 0 or 1 not only one . Is there any way to do that or not?
Eric
Eric 2015-4-6
I haven't the slightest idea what you're trying to accomplish, but all im2bw does is threshold an image. If you're not supplying the second argument (level), the default value of 0.5 is used. For an input image that is floating point then all pixel values greater than 0.5 will be 1. That's why im2bw is giving you all ones. The output of im2bw is a logical array and clearly not appropriate for whatever it is you're trying to do.

请先登录,再进行评论。

回答(2 个)

Stephen23
Stephen23 2015-4-6
编辑:Stephen23 2015-4-7
This is an ill-defined problem, unless you specify what encoding method you want to convert decimal fractions. MATLAB only has dec2bin which converts integer values only. This is a topic that has been discussed before on MATLAB Answers, and even some other forums:
Although it is important to note that the problem is ill-defined, because "There is no one right answer on how to represent a fractional number in binary" (quoted from Peter at the last link).

Mahdiyar
Mahdiyar 2015-4-6
Hi Ameligege
It is simple . you can use the function de2bi instead of dec2bi.
regards,
  1 个评论
Ameligege
Ameligege 2015-4-6
An error occur when I test it on single value
de2bi(77.125)
Error using de2bi (line 127) Input must contain only finite real nonnegative integers.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Data Type Conversion 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by