Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
int2bin vector

Subject: int2bin vector

From: Sagar Nepali

Date: 18 May, 2005 17:16:49

Message: 1 of 9

Can anybody help me convert an integer (or byte) into a vector of
binary bits in the SIMULINK.
As an example, if the input is 159 (0x9F) then the output must be
[1,0,0,1,1,1,1,1].
Thank you.
Sagar

Subject: int2bin vector

From: us

Date: 18 May, 2005 17:31:18

Message: 2 of 9

Sagar Nepali:
<SNIP <int2bin> ... or ... wasn't it <dec2bin>...

     dec2bin(159)
% -or-
     dec2bin(159)-'0'

us
ps: sorry CSSMer oldies for reaching for this low hanging fruit so
quickly

Subject: int2bin vector

From: Pascual Benito

Date: 18 May, 2005 18:52:44

Message: 3 of 9

DEC2BIN will only produce a text string with the binary bits (e.g.
'011001101'), you will then have to convert this char string into the
vector. If you want to directly get a numerical array with the binary
bits you can use the BITGET command:
for example:

%get the first 32 bits of binary representation of 159, and store in
a text string, s
>> s=dec2bin(159,32)
s =
00000000000000000000000010011111

%get bits 1 through 32 of decimal number 159 and store values in a
vector, v, with lowest order bits on the left
>> v=bitget(159,1:32)
v =
  Columns 1 through 15
     1 1 1 1 1 0 0 1 0 0 0
 0 0 0 0
  Columns 16 through 30
     0 0 0 0 0 0 0 0 0 0 0
 0 0 0 0
  Columns 31 through 32
     0 0

>>whos
  s 1x32 64 char array
  v 1x32 256 double array

us wrote:
>
>
> Sagar Nepali:
> <SNIP <int2bin> ... or ... wasn't it <dec2bin>...
>
> dec2bin(159)
> % -or-
> dec2bin(159)-'0'
>
> us
> ps: sorry CSSMer oldies for reaching for this low hanging fruit so
> quickly

Subject: int2bin vector (Clarification)

From: Sagar Nepali

Date: 18 May, 2005 20:51:15

Message: 4 of 9

By INT2BIN VECTOR, I did not mean the function "dec2bin" but any
INTEGER that is to be converted to a VECTOR of BINARY digits as "0"s
and "1"s.
Sorry for the confusion.

us wrote:
>
>
> Sagar Nepali:
> <SNIP <int2bin> ... or ... wasn't it <dec2bin>...
>
> dec2bin(159)
> % -or-
> dec2bin(159)-'0'
>
> us
> ps: sorry CSSMer oldies for reaching for this low hanging fruit so
> quickly

Subject: int2bin vector

From: Sagar Nepali

Date: 18 May, 2005 21:29:21

Message: 5 of 9

Thank you for your reply. You precisely understood my requirement
but I need it in Simulink.
Please suggest me if there is a similar way.
Thank you

Pascual Benito wrote:
>
>
> DEC2BIN will only produce a text string with the binary bits (e.g.
> '011001101'), you will then have to convert this char string into
> the
> vector. If you want to directly get a numerical array with the
> binary
> bits you can use the BITGET command:
> for example:
>
> %get the first 32 bits of binary representation of 159, and store
> in
> a text string, s
>>> s=dec2bin(159,32)
> s =
> 00000000000000000000000010011111
>
> %get bits 1 through 32 of decimal number 159 and store values in a
> vector, v, with lowest order bits on the left
>>> v=bitget(159,1:32)
> v =
> Columns 1 through 15
> 1 1 1 1 1 0 0 1 0 0 0
>
> 0 0 0 0
> Columns 16 through 30
> 0 0 0 0 0 0 0 0 0 0 0
>
> 0 0 0 0
> Columns 31 through 32
> 0 0
>
>>>whos
> s 1x32 64 char array
> v 1x32 256 double array
>
> us wrote:
>>
>>
>> Sagar Nepali:
>> <SNIP <int2bin> ... or ... wasn't it
<dec2bin>...
>>
>> dec2bin(159)
>> % -or-
>> dec2bin(159)-'0'
>>
>> us
>> ps: sorry CSSMer oldies for reaching for this low hanging fruit
> so
>> quickly

Subject: int2bin vector

From: Amistad

Date: 19 May, 2005 13:54:25

Message: 6 of 9

Hi, Laura:
decimal to binary: Integer to binary conversion
http://www.mathworks.com/access/helpdesk/help/toolbox/commblks/ref/integertobitconverter.html

binary to decimal: binary to integer conversion
http://www.mathworks.com/access/helpdesk/help/toolbox/commblks/ref/bittointegerconverter.html


--
Amistad Hou



"Sagar Nepali" <sagarnepali@hotmail.com> ???
news:ef065d7.-1@webx.raydaftYaTP ???...
> Can anybody help me convert an integer (or byte) into a vector of
> binary bits in the SIMULINK.
> As an example, if the input is 159 (0x9F) then the output must be
> [1,0,0,1,1,1,1,1].
> Thank you.
> Sagar

Subject: int2bin vector

From: Sagar Nepali

Date: 19 May, 2005 18:11:42

Message: 7 of 9

Thanks a lot for your suggestions.
I am using TI C2000 for TMS320F2812. I need to put a result (a byte)
on the digital output, which will later be picked up by a DAC. C2000
compiler does not accept s-function block "Integer to binary
conversion". Could anybody suggest me a way out?

Amistad wrote:
>
>
> Hi, Laura:
> decimal to binary: Integer to binary conversion
> <http://www.mathworks.com/access/helpdesk/help/toolbox/commblks/ref/integertobitconverter.html>
>
> binary to decimal: binary to integer conversion
> <http://www.mathworks.com/access/helpdesk/help/toolbox/commblks/ref/bittointegerconverter.html>
>
>
> --
> Amistad Hou
>
>
>
> "Sagar Nepali" <sagarnepali@hotmail.com> ???
> news:ef065d7.-1@webx.raydaftYaTP ???...
>> Can anybody help me convert an integer (or byte) into a vector
of
>> binary bits in the SIMULINK.
>> As an example, if the input is 159 (0x9F) then the output must
be
>> [1,0,0,1,1,1,1,1].
>> Thank you.
>> Sagar
>
>
>

Subject: int2bin vector

From: Amistad

Date: 20 May, 2005 08:25:09

Message: 8 of 9

i assume what you want to perform is bit-operation on
integer varible. for example,
a=12;
b=0x01;
c = a&b = 1;
i suggest you using "data type conversion"
http://www.mathworks.com/access/helpdesk/help/toolbox/simulink/slref/datatypeconversion.html#842904
to convert a float variable to a proper precision fixed point first.
then, use elements in "Logic and Bit Operations " sub-libary to complete
your model.

--
Amistad Hou



"Sagar Nepali" <sagarnepali@hotmail.com> ??? news:ef065d7.5@webx.raydaftYaTP
???...
> Thanks a lot for your suggestions.
> I am using TI C2000 for TMS320F2812. I need to put a result (a byte)
> on the digital output, which will later be picked up by a DAC. C2000
> compiler does not accept s-function block "Integer to binary
> conversion". Could anybody suggest me a way out?
>
> Amistad wrote:
> >
> >
> > Hi, Laura:
> > decimal to binary: Integer to binary conversion
> >
<http://www.mathworks.com/access/helpdesk/help/toolbox/commblks/ref/integert
obitconverter.html>
> >
> > binary to decimal: binary to integer conversion
> >
<http://www.mathworks.com/access/helpdesk/help/toolbox/commblks/ref/bittoint
egerconverter.html>
> >
> >
> > --
> > Amistad Hou
> >
> >
> >
> > "Sagar Nepali" <sagarnepali@hotmail.com> ???
> > news:ef065d7.-1@webx.raydaftYaTP ???...
> >> Can anybody help me convert an integer (or byte) into a vector
> of
> >> binary bits in the SIMULINK.
> >> As an example, if the input is 159 (0x9F) then the output must
> be
> >> [1,0,0,1,1,1,1,1].
> >> Thank you.
> >> Sagar
> >
> >
> >

Subject: int2bin vector

From: Norbert

Date: 20 May, 2005 06:19:48

Message: 9 of 9

Sagar Nepali wrote:
>
>
> Can anybody help me convert an integer (or byte) into a vector of
> binary bits in the SIMULINK.
> As an example, if the input is 159 (0x9F) then the output must be
> [1,0,0,1,1,1,1,1].
> Thank you.
> Sagar

I'm not sure about Simulink, but in Matlab simply use

str2num(dec2bin(159)')'

NM

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us