# Data type conversion in matlab

1. Jun 18, 2008

### xentity1x

I'm writing a program in matlab. I have a matrix whose entries are all ones and zeros. I want to convert each row vector of the matrix into a binary number whose digits are the entries of the vector. So for example if an arbitrary row of the matrix was [1, 0, 1, 1], I would like to convert it into the binary number 1011. How would I go about doing that? My end goal is to convert that binary number into a base ten one, but I already know how to do that.

2. Jun 19, 2008

### eys_physics

Well, it could be done by using the following simple formula:
$$nbr=\sum_{i=1}^{N}a_{i}10^{N-i}$$

where a_i are the elements of the vector and N is the dimension.

3. Feb 7, 2011

### Salomon

In case you have numeric (double integer) valued matrix components, then you can use the following MATLAB conversion:

B=dec2bin(A);

then back to double integer you can convert using:
C=bin2dec(B); % NB: You will loose however decimal points

Hopefully that helps you.