PDA

View Full Version : Formatted String


udayakumar
06-30-04, 03:12 PM
Hi,

How can I store a series of numbers in a string in the following format,

"N1,N2,N3,....Nn"

where N1,N2,N3 etc are real numbers.

I am new to forth and I really cannot understand the string routines given in the examples page.

Thanks in Advance.

RMDumse
07-02-04, 10:05 AM
Well, as a concept, storing floats in a string (as an end goal) is rather an unusual thing to do in IsoMax(TM). Usually floats live as constants, or variables, or on the stack. Strings are done for input / output processing. So I'm not sure exactly how to answer your question.

Do you want to create a string for output?

The answer might be as simple as, putting the string in a ." word. Example:

." 123.45E9, 55.0E0"


Do you want to read a string as input?

Generally this is done with use of NUMBER or EVALUATE or INTERPRET.


Or am I missing the point?

Please narrow the scope a bit for me, so I know how I may help.

udayakumar
07-02-04, 11:24 AM
I want to send a set of numbers to a PC through the serial port, SCI1 . I am using your word SCI1-TYPE to send a string through SCI1

: SCI1-TYPE
BEGIN
DUP 0= NOT
WHILE
1- SWAP DUP @ SCI1 TX 1+ SWAP
REPEAT
2DROP
; EEWORD

I want to store my numbers in a string and use the above word to send it through SCI1.
ThankYou

RMDumse
07-02-04, 03:47 PM
Oh yes. You were just asking about about vectored serial routines a few days ago. Well... perhaps you should email LC and ask to test our V0.77. Largely prompted by your question, I had the language updated to allow vectored the serial so you could redirect the normally formated output to SCI1 (or any other output channel for that matter). So if you're willing to test this, (we haven't gotten to it yet it is so newly done) we would like you to try. It would solve the problem.

On the other hand... to answer your question. Formatted output is done through use of a few formating words. Please read up on <# # and #>. These words allow base conversion of numbers into strings. They work backwards from the least significant digit, to the most. They work on double numbers from the stack. So formating for floats is a bit more complicated, as you have to do the base number (mantissa), then the exponent.

Well, I could go further, but let's decide if V0.77 might be a better solution for you. Do you have a JTAG and a non-disclosure agreement so we can send you a replacement kernel?