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

19 views (last 30 days)

Show older comments

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 Comments

Eric
on 6 Apr 2015

### Answers (2)

Stephen23
on 6 Apr 2015

Edited: Stephen23
on 7 Apr 2015

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

##### 0 Comments

Mahdiyar
on 6 Apr 2015

Hi Ameligege

It is simple . you can use the function de2bi instead of dec2bi.

regards,

### See Also

### Categories

### Community Treasure Hunt

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

Start Hunting!