From: Ujjwal Verma on
Hello,

I am having problem with dec2binvec, which converts decimal to binary vector.

Please compare the output of the following two lines:
1) dec2binvec(65,7)

ans =

1 0 0 0 0 0 1

2)dec = 65;
binary2 = dec2binvec(dec,7)

binary2 =

0 0 1 0 0 0 1


Why is the difference in the LSB? I tried with different numbers, and its is same in all the case. Why is dec2binvec is not converting correctly?

Thanks in advance
From: us on
"Ujjwal Verma" <toto(a)gt.tyuu> wrote in message <htlepc$sbe$1(a)fred.mathworks.com>...
> Hello,
>
> I am having problem with dec2binvec, which converts decimal to binary vector.
>
> Please compare the output of the following two lines:
> 1) dec2binvec(65,7)
>
> ans =
>
> 1 0 0 0 0 0 1
>
> 2)dec = 65;
> binary2 = dec2binvec(dec,7)
>
> binary2 =
>
> 0 0 1 0 0 0 1
>
>
> Why is the difference in the LSB? I tried with different numbers, and its is same in all the case. Why is dec2binvec is not converting correctly?
>
> Thanks in advance

it works here
- r2010a.32
- daq tbx 2.16
- which versions do you have(?)...
- what do you see after

which dec2binvec;
which dec2bin;

us
From: Ujjwal Verma on
"us " <us(a)neurol.unizh.ch> wrote in message <htlk42$g2j$1(a)fred.mathworks.com>...
> "Ujjwal Verma" <toto(a)gt.tyuu> wrote in message <htlepc$sbe$1(a)fred.mathworks.com>...
> > Hello,
> >
> > I am having problem with dec2binvec, which converts decimal to binary vector.
> >
> > Please compare the output of the following two lines:
> > 1) dec2binvec(65,7)
> >
> > ans =
> >
> > 1 0 0 0 0 0 1
> >
> > 2)dec = 65;
> > binary2 = dec2binvec(dec,7)
> >
> > binary2 =
> >
> > 0 0 1 0 0 0 1
> >
> >
> > Why is the difference in the LSB? I tried with different numbers, and its is same in all the case. Why is dec2binvec is not converting correctly?
> >
> > Thanks in advance
>
> it works here
> - r2010a.32
> - daq tbx 2.16
> - which versions do you have(?)...
> - what do you see after
>
> which dec2binvec;
> which dec2bin;
>
> us



Mine version is 7.6.0.324 (R2008a) .
daq toolbox is 2.12

which dec2binvec n dec2bin gives this
C:\Program Files\MATLAB\R2008a\toolbox\daq\daq\dec2binvec.m and
C:\Program Files\MATLAB\R2008a\toolbox\matlab\strfun\dec2bin.m resp
From: us on
"Ujjwal Verma"
> Mine version is 7.6.0.324 (R2008a) .
> daq toolbox is 2.12
>
> which dec2binvec n dec2bin gives this
> C:\Program Files\MATLAB\R2008a\toolbox\daq\daq\dec2binvec.m and
> C:\Program Files\MATLAB\R2008a\toolbox\matlab\strfun\dec2bin.m resp

hmm......

dec2binvec(65,7)
% ans = 1 0 0 0 0 0 1
dec=65;
dec2binvec(dec,7)
% ans = 1 0 0 0 0 0 1
% what do you get with
dec2bin(dec,7)
% ans = 1000001
% also,
edit dec2binvec; % <- don't touch it, though
% put a break right before the line (r2010a!)
% out = logical(str2num([fliplr(out);blanks(length(out))]')');
% run your example, then inspect the var OUT before this conversion...

us
From: Ujjwal Verma on
"us " <us(a)neurol.unizh.ch> wrote in message <htlmb8$bim$1(a)fred.mathworks.com>...
> "Ujjwal Verma"
> > Mine version is 7.6.0.324 (R2008a) .
> > daq toolbox is 2.12
> >
> > which dec2binvec n dec2bin gives this
> > C:\Program Files\MATLAB\R2008a\toolbox\daq\daq\dec2binvec.m and
> > C:\Program Files\MATLAB\R2008a\toolbox\matlab\strfun\dec2bin.m resp
>
> hmm......
>
> dec2binvec(65,7)
> % ans = 1 0 0 0 0 0 1
> dec=65;
> dec2binvec(dec,7)
> % ans = 1 0 0 0 0 0 1
> % what do you get with
> dec2bin(dec,7)
> % ans = 1000001
> % also,
> edit dec2binvec; % <- don't touch it, though
> % put a break right before the line (r2010a!)
> % out = logical(str2num([fliplr(out);blanks(length(out))]')');
> % run your example, then inspect the var OUT before this conversion...
>
> us

i tried now with dec=29 and found that
out =

0011100

If we do the other way around,ie if we suppose
binary =

1 0 1 1 1 0 0

then binvec2dec(binary) gives

ans =

29