# How to convert in Matlab a binary data [1 0 1 0] to an integer number ?

Status
Not open for further replies.

#### mona_c

##### Junior Member level 1 hi

cany any one help in matlb formats...i want to reduce to gape b/w the bits in a no. e.g. 1 0 1 0 is the binary no. i want this no. as 1010..i.e. without the space b/w the bits..or vice versa.can i do so using matlab?

Mona

#### aboozar.hamidipoor

##### Full Member level 3 matlab dec2binvec

hello mona_c;

as you know, in matlab the sequence of [1 0 1 0] and  are different. in fact the former is a binary data with the length of 4 and the latter is an integer number and hence, if you want to convert a binary data such as [1 0 1 0] to an integer number such as  you could use this procedure:

=1×10^4 + 0×10^3 + 1×10^2 + 0×10^0;

or in general sence:

a=[1 0 1 0] ;
b=0;
for i=1:length(a)
b=a(i)*10^(length(a)-i)+b;
end;
b

good luck.

#### hermin

##### Full Member level 2 dec2binvec matlab

try to use bin2binvec, i dont remember the exact code, but binary vector has the format that you want, if you are using decimal numbers and converting it to binary vector, use dec2binvec(decimal number), for more info, type 'help dec2binvec' on the matlab command line

#### mona_c

##### Junior Member level 1 bin to vector matlab

aboozar.hamidipoor said:
hello mona_c;

as you know, in matlab the sequence of [1 0 1 0] and  are different. in fact the former is a binary data with the length of 4 and the latter is an integer number and hence, if you want to convert a binary data such as [1 0 1 0] to an integer number such as  you could use this procedure:

=1×10^4 + 0×10^3 + 1×10^2 + 0×10^0;

or in general sence:

a=[1 0 1 0] ;
b=0;
for i=1:length(a)
b=a(i)*10^(length(a)-i)+b;
end;
b

good luck.

but u dint get my ques....i m not converting the no. from bin to dec....i wanna change the look of the same no. .i.e the same bin no. one with spaces...& one with no spaces b/w the bits of the no. hope i m clear now

hermin said:
try to use bin2binvec, i dont remember the exact code, but binary vector has the format that you want, if you are using decimal numbers and converting it to binary vector, use dec2binvec(decimal number), for more info, type 'help dec2binvec' on the matlab command line
hello hermin

there is no such command as bin2bin even.....any other option? plzz

#### karim.elmahdy

##### Junior Member level 2 matlab binary vector

Dear mona_c

what you wanna do is actually not possible in matlab, you cannot change the display properties and make it works with two different settings on the same time.

sorry

Status
Not open for further replies.