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:
converting alphanumeric to binary or floating point

Subject: converting alphanumeric to binary or floating point

From: Jess J

Date: 13 Jan, 2009 13:20:03

Message: 1 of 3

Hi, can anyone guide me on converting alphanumeric into the form of binary or floating point? What method can be used for the conversion.
Thanks in advance.

Subject: converting alphanumeric to binary or floating point

From: Roger Stafford

Date: 13 Jan, 2009 13:36:03

Message: 2 of 3

"Jess J" <jessie_jtl@yahoo.co.uk> wrote in message <gki4e3$n27$1@fred.mathworks.com>...
> Hi, can anyone guide me on converting alphanumeric into the form of binary or floating point? What method can be used for the conversion.
> Thanks in advance.

  Converting to floating point is what matlab's expressions such as "x = -1.234e7" do very well. Moreover its internal representation is in binary. Do you have something else in mind?

Roger Stafford

Subject: converting alphanumeric to binary or floating point

From: Jess J

Date: 14 Jan, 2009 13:53:02

Message: 3 of 3

"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <gki5c3$oae$1@fred.mathworks.com>...
> "Jess J" <jessie_jtl@yahoo.co.uk> wrote in message <gki4e3$n27$1@fred.mathworks.com>...
> > Hi, can anyone guide me on converting alphanumeric into the form of binary or floating point? What method can be used for the conversion.
> > Thanks in advance.
>
> Converting to floating point is what matlab's expressions such as "x = -1.234e7" do very well. Moreover its internal representation is in binary. Do you have something else in mind?
>
> Roger Stafford

Hi, Roger. Thanks for your response.
For your information, i need to convert them a large number of data (e.g. 100 sets of data to binary). Today I found a file in File Exchange, title:Encode and Decode ASCII Binary. However, i failed to run that. And I didn't know where's my problem. Maybe you can help me have a look on it? (I am a new user of Matlab). Thanks for your help

function encode(test.txt,output.txt)
wpl=0;
[spc_ent,C0]=textread('code.m','%s %s',2);
[L,C]=textread('code.m','%s %s','headerlines',2);
L=char(L);
FID = fopen('test.txt','r');
OUT = fopen('output.txt','w');
while 1
    tline = fgetl(FID);
    if ~ischar(tline), break, end
    for i=1:size(tline,2)
        x=find(L==tline(i));
        if isempty(x)==1
            fprintf(OUT,'%s',char(C0(1)));
            wpl=wpl+1;
        else
            fprintf(OUT,'%s',char(C(x)));
            wpl=wpl+1;
        end
        if wpl==10, fprintf(OUT,'\n');, wpl=0;, end
    end
    fprintf(OUT,char(C0(2)));
    wpl=wpl+1;
end
fclose('all');

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