[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Thanks Re: Loading hex data
From: |
Philip Nienhuis |
Subject: |
Re: Thanks Re: Loading hex data |
Date: |
Mon, 17 Sep 2012 11:55:12 -0700 (PDT) |
ionavideo wrote
>
> Thanks. I really appreciate the suggestions. I tried both dlmread and
> textread. With textread I get an "error" I can sort of work with.
>
> Here is the data file keydata.txt:
> 32
> 51
> 0b
> a9
> ba
>
> So we have 5 hexadecimal numbers separated by CR-LF
>
> And here is the Octave line:
>
> k= hex2dec(textread("keydata.txt", "%d"))
>
> And the output from running the test program is:
> k =
> 0
> 3
> 0
> 0
> 0
>
> Which is not a correct translation of "32 51 0b a9 ba" because
> 32 hex equals 50 dec or the ascii "2"
> and 51 hex equals dec 81 or ascii "Q", etc.
>
> Yes, I tried other ways to format the line, as follows:
>
> #k= hex2dec(textread("keydata.txt", "%x"))
> # the above gives "error: Invalid call to hex2dec. Correct usage is
> hex2dec(S)
>
> #k= hex2dec(textread("keydata.txt", "%s"))
> #the above gives several errors, including: 'string undefined ... called
> from
> # ... toascii.m
> # error evaluating argument list element number 1
> # error ... strjust.m
> # error ... base2dec.m
> # errpr ... hex2dec.m
>
Looks like a bug somewhere, but unclear whether it is in textread. See below
> ---------------------------------------------------------
> So my question is, should I be using
> %s
> or
> %d
>
%s
What Octave version do you use?
And what is the output of:
textread("keydata.txt", "%s")
?
Philip
--
View this message in context:
http://octave.1599824.n4.nabble.com/Thanks-Re-Loading-hex-data-tp4644214p4644231.html
Sent from the Octave - General mailing list archive at Nabble.com.